Skip to content
This repository was archived by the owner on Jun 9, 2022. It is now read-only.
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
Binary file added RapidFTR-Android/res/drawable/bgbtnphoto.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RapidFTR-Android/res/drawable/bgbtnphotohover.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions RapidFTR-Android/res/drawable/camera_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/bgbtnphotohover"
android:state_focused="true"
/>
<item android:drawable="@drawable/bgbtnphoto"/>

</selector>
8 changes: 5 additions & 3 deletions RapidFTR-Android/res/layout/form_photo_upload_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
<include layout="@layout/form_help_text" />

<Button android:id="@+id/thumbnail"
android:background="@drawable/button"
android:layout_width="fill_parent"
android:background="@drawable/camera_button"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/photo_capture">
android:layout_gravity="center"
android:text="@string/photo_capture"
>
</Button>

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down
14 changes: 14 additions & 0 deletions RapidFTR-Android/res/menu/view_children_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/synchronize_all"
android:title="@string/synchronize_all"/>
<item android:id="@+id/cancel_synchronize_all"
android:title="@string/cancel_synchronize_all"/>
<item android:id="@+id/logout"
android:title="@string/log_out"/>
<item android:id="@+id/info" android:icon="@drawable/ic_info"
android:title="@string/info"/>
<item android:id="@+id/sort_by" android:title="@string/sort_by"/>
</menu>
6 changes: 6 additions & 0 deletions RapidFTR-Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<string name="log_in">Log In</string>
<string name="log_out">Log Out</string>
<string name="confirm_logout_message">Records are still being sychronised. Logging out now will cancel this process, are you sure you want to log out?</string>
<string name="session_timeout">Your session is not active on the server, Please logout and login again</string>

<string name="logout_successful">You have been logged out successfully.</string>
<string name="change_url">Change URL</string>
<string name="register_child">Register Child</string>
Expand Down Expand Up @@ -91,6 +93,10 @@

<string name="this_is_audio_upload_box">This is an audio upload box</string>
<string name="info">Info</string>
<string name="sort_by">Sort by</string>
<string name="sort_by_options">Sort by</string>
<string name="sort_by_name">Name</string>
<string name="sort_by_recent_update">Recently Updated</string>

<string name="info_text">RapidFTR is supported in the following languages:</string>
<string name="full_name_label">Full name:</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public abstract class RapidFtrActivity extends FragmentActivity {

protected @Getter @Setter Menu menu;

int menuId = R.menu.options_menu;

private BroadcastReceiver networkChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down Expand Up @@ -131,7 +133,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (getContext().isLoggedIn()) {
getMenuInflater().inflate(R.menu.options_menu, menu);
getMenuInflater().inflate(menuId, menu);
setMenu(menu);
toggleSync(menu);
setContextToSyncTask();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,92 @@
package com.rapidftr.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.widget.ListView;
import com.rapidftr.R;
import com.rapidftr.adapter.ChildViewAdapter;
import com.rapidftr.model.Child;
import com.rapidftr.repository.ChildRepository;
import lombok.Cleanup;
import lombok.Getter;
import lombok.Setter;
import org.json.JSONException;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ViewAllChildrenActivity extends RapidFtrActivity {

@Getter @Setter List<Child> children;
@Getter @Setter ChildViewAdapter childViewAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_all_children);
listView(getChildren());
menuId = R.menu.view_children_menu;
this.children = getChildren();
listView();
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.sort_by) {
showSortOptions();
return true;
}
return super.onOptionsItemSelected(item);
}

private void showSortOptions() {
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener(){

@Override
public void onClick(DialogInterface dialogInterface, int item) {
switch (item){
case 0:
sortChildrenByName();
break;
case 1:
sortChildrenByRecentUpdate();
break;
}
}
};
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle(getString(R.string.sort_by_options)).setCancelable(false);
alertDialog.setItems(new String[]{getString(R.string.sort_by_name), getString(R.string.sort_by_recent_update)}, listener);
alertDialog.create().show();
}

public void sortChildrenByRecentUpdate() {
Collections.sort(this.children, new Comparator<Child>() {
@Override
public int compare(Child child, Child child1) {
Timestamp childLastUpdateAt = Timestamp.valueOf(child.getLastUpdatedAt());
Timestamp child1LastUpdateAt = Timestamp.valueOf(child1.getLastUpdatedAt());
return child1LastUpdateAt.compareTo(childLastUpdateAt);
}
});
childViewAdapter.notifyDataSetChanged();
}

public void sortChildrenByName() {
Collections.sort(this.children, new Comparator<Child>() {
@Override
public int compare(Child child, Child child1) {
return child.getName().compareTo(child1.getName());
}
});
childViewAdapter.notifyDataSetChanged();
}

private List<Child> getChildren()
{
List<Child> children = new ArrayList<Child>();
Expand All @@ -35,10 +100,11 @@ private List<Child> getChildren()
return children;
}

private void listView(List<Child> children) {
ChildViewAdapter childViewAdapter = new ChildViewAdapter(this, R.layout.row_child, children);
private void listView() {
childViewAdapter = new ChildViewAdapter(this, R.layout.row_child, this.children);

ListView childListView = (ListView) findViewById(R.id.child_list);
if (children.isEmpty()) {
if (this.children.isEmpty()) {
childListView.setEmptyView(findViewById(R.id.no_child_view));
}
childListView.setAdapter(childViewAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

public class ImageAdapter extends BaseAdapter {

private final Child child;
public static final int NO_PADDING = 0;

private final Child child;
private final boolean enabled;
private final PhotoCaptureHelper photoCaptureHelper;
private final Context context;
Expand Down Expand Up @@ -53,7 +55,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
try {
bitmap = photoCaptureHelper.getThumbnailOrDefault(photoKeys.get(position).toString());
imageView = new ImageView(context);
imageView.setPadding(0,0,0,0);
imageView.setPadding(NO_PADDING, NO_PADDING, NO_PADDING, NO_PADDING);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected void setCreatedAt(String createdAt) throws JSONException {
put(created_at.getColumnName(), createdAt);
}

public String getLastUpdatedAt() throws JSONException {
public String getLastUpdatedAt(){
return optString(last_updated_at.getColumnName(), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.rapidftr.utils.RapidFtrDateTime;
import com.rapidftr.utils.http.FluentRequest;
import com.rapidftr.utils.http.FluentResponse;
import org.apache.http.HttpException;
import org.apache.http.HttpResponse;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.JSONArray;
Expand Down Expand Up @@ -251,9 +252,9 @@ public HttpResponse getAudio(Child child) throws IOException {

}

public HashMap<String, String> getAllIdsAndRevs() throws IOException {
public HashMap<String, String> getAllIdsAndRevs() throws IOException, HttpException {
final ObjectMapper objectMapper = new ObjectMapper();
HttpResponse response = fluentRequest.path("/children-ids").context(context).get();
HttpResponse response = fluentRequest.path("/children-ids").context(context).get().ensureSuccess();
List<Map> idRevs = asList(objectMapper.readValue(response.getEntity().getContent(), Map[].class));
HashMap<String, String> idRevMapping = new HashMap<String, String>();
for (Map idRev : idRevs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.rapidftr.RapidFtrApplication;
import com.rapidftr.activity.LoginActivity;
import com.rapidftr.activity.RapidFtrActivity;
import com.rapidftr.utils.http.FluentRequest;

import java.io.FileReader;
import java.io.IOException;

import static android.widget.Toast.LENGTH_LONG;
Expand All @@ -24,10 +26,11 @@ public void attemptLogOut(RapidFtrActivity currentActivity) {
logOut(currentActivity);
}

private void logOut(RapidFtrActivity currentActivity) {
protected void logOut(RapidFtrActivity currentActivity) {
try {
RapidFtrApplication context = currentActivity.getContext();
context.setCurrentUser(null);
FluentRequest.getHttpClient().getCookieStore().clear();
Toast.makeText(context, R.string.logout_successful, LENGTH_LONG).show();
currentActivity.finish();
currentActivity.startActivity(new Intent(currentActivity, LoginActivity.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected void onPostExecute(User user) {
if (user == null)
throw new GeneralSecurityException();

user.save();
application.setCurrentUser(user);
getFormSections(user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.rapidftr.repository.ChildRepository;
import com.rapidftr.service.ChildService;
import com.rapidftr.service.FormService;
import org.apache.http.HttpException;
import org.json.JSONException;

import java.io.IOException;
Expand All @@ -22,7 +23,7 @@ public SyncAllDataAsyncTask(FormService formService, ChildService childService,
super(formService, childService, childRepository, user);
}

protected void sync() throws JSONException, IOException {
protected void sync() throws JSONException, IOException, HttpException {
ArrayList<String> idsToDownload = getAllIdsForDownload();
List<Child> childrenToSyncWithServer = childRepository.toBeSynced();
setProgressBarParameters(idsToDownload, childrenToSyncWithServer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.rapidftr.repository.ChildRepository;
import com.rapidftr.service.ChildService;
import com.rapidftr.service.FormService;
import org.apache.http.HttpException;
import org.json.JSONException;

import java.io.IOException;
Expand Down Expand Up @@ -64,6 +65,11 @@ protected Boolean doInBackground(Void... notRelevant) {
try {
sync();
return true;
} catch (HttpException e) {
notificationManager.cancel(NOTIFICATION_ID);
Log.e("SyncAllDataTask", "Error in sync", e);
publishProgress(context.getString(R.string.session_timeout));
return false;
} catch (Exception e) {
notificationManager.cancel(NOTIFICATION_ID);
Log.e("SyncAllDataTask", "Error in sync", e);
Expand All @@ -72,7 +78,7 @@ protected Boolean doInBackground(Void... notRelevant) {
}
}

protected abstract void sync() throws JSONException, IOException;
protected abstract void sync() throws JSONException, IOException, HttpException;


private void configureNotification() {
Expand All @@ -94,7 +100,7 @@ void setProgressBarParameters(ArrayList<String> idsToDownload, List<Child> child
maxProgress = totalRecordsToSynchronize + formSectionProgress;
}

public ArrayList<String> getAllIdsForDownload() throws IOException, JSONException {
public ArrayList<String> getAllIdsForDownload() throws IOException, JSONException, HttpException {
HashMap<String,String> serverIdsRevs = childService.getAllIdsAndRevs();
HashMap<String, String> repoIdsAndRevs = childRepository.getAllIdsAndRevs();
ArrayList<String> idsToDownload = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@

public class PhotoCaptureHelper extends CaptureHelper {

public PhotoCaptureHelper(RapidFtrApplication context) {
public static final int THUMBNAIL_WIDTH = 96;
public static final int THUMBNAIL_HEIGHT = 96;
public static final int JPEG_QUALITY = 85;
public static final int PHOTO_WIDTH = 475;
public static final int PHOTO_HEIGHT = 635;

public PhotoCaptureHelper(RapidFtrApplication context) {
super(context);
}

Expand Down Expand Up @@ -90,24 +96,41 @@ public Bitmap getDefaultThumbnail() {
}

public void savePhoto(Bitmap bitmap, int rotationDegree, String fileNameWithoutExtension) throws IOException, GeneralSecurityException {
save(rotateBitmap(scaleImageTo(bitmap, 475, 635), rotationDegree), fileNameWithoutExtension);
Bitmap rotated = rotateBitmap(bitmap, rotationDegree);
Bitmap scaled = scaleImageTo(rotated, PHOTO_WIDTH, PHOTO_HEIGHT);
save(scaled, fileNameWithoutExtension);
}

protected Bitmap scaleImageTo(Bitmap image, int width, int height) {
protected Bitmap resizeImageTo(Bitmap image, int width, int height) {
return Bitmap.createScaledBitmap(image, width, height, false);
}

protected Bitmap scaleImageTo(Bitmap image, int maxWidth, int maxHeight) {
double givenWidth = image.getWidth(), givenHeight = image.getHeight();
double scaleRatio = 1.0;

if (givenWidth > maxWidth || givenHeight > maxHeight) {
if (givenWidth > givenHeight) {
scaleRatio = maxWidth / givenWidth;
} else {
scaleRatio = maxHeight / givenHeight;
}
}

return resizeImageTo(image, (int) (givenWidth * scaleRatio), (int) (givenHeight * scaleRatio));
}

protected void save(Bitmap bitmap, String fileNameWithoutExtension) throws IOException, GeneralSecurityException {
fileNameWithoutExtension = fileNameWithoutExtension.contains(".jpg")? fileNameWithoutExtension : fileNameWithoutExtension + ".jpg";
File file = new File(getDir(), fileNameWithoutExtension);
if (!file.exists())
file.createNewFile();
@Cleanup OutputStream outputStream = getCipherOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, outputStream);
bitmap.compress(Bitmap.CompressFormat.JPEG, JPEG_QUALITY, outputStream);
}

public void saveThumbnail(Bitmap bitmap, int rotationDegree, String fileNameWithoutExtension) throws IOException, GeneralSecurityException {
save(rotateBitmap(scaleImageTo(bitmap, 96, 96), rotationDegree), fileNameWithoutExtension + "_thumb");
save(resizeImageTo(rotateBitmap(bitmap, rotationDegree), THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT), fileNameWithoutExtension + "_thumb");
}

public Bitmap loadThumbnail(String fileNameWithoutExtension) throws IOException, GeneralSecurityException {
Expand Down
Loading