Commit 7e656252 authored by Mahendri Dwicahyo's avatar Mahendri Dwicahyo

Merge branch 'aku' into 'master'

Fixing Small Error

See merge request mahendri.md/capi-stis!4
parents ab1884d7 5b8e2c40
......@@ -342,7 +342,7 @@ the specific language governing permissions and limitations under the License.
<provider
android:name=".revalidasi.custom.NotifDataProvider"
android:authorities="org.odk.collect.android.provider.odk.briefdata"
android:authorities="org.odk.collect.android.provider.odk.notifdata"
android:exported="false" />
<service
android:name=".revalidasi.notifikasi.MyFirebaseMessagingService">
......
......@@ -1864,6 +1864,9 @@ public class FormEntryActivity extends SlidingActivity implements AnimationListe
return false;
}
/**
* modifikasi untuk CAPI-STIS menu log error dan hirarki swipe
*/
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
......@@ -1903,29 +1906,49 @@ public class FormEntryActivity extends SlidingActivity implements AnimationListe
beenSwiped = true;
if (velocityX > 0) {
if (e1.getX() > e2.getX()) {
Timber.e("showNextView VelocityX is bogus! %f > %f", e1.getX(), e2.getX());
Collect.getInstance().getActivityLogger()
.logInstanceAction(this, "onFling", "showNext");
showNextView(false);
if (getSlidingMenu().isMenuShowing()) {
toggleLeftMenu();
beenSwiped = false;
} else {
Timber.e("showNextView VelocityX is bogus! %f > %f", e1.getX(), e2.getX());
Collect.getInstance().getActivityLogger()
.logInstanceAction(this, "onFling", "showNext");
showNextView(false);
}
} else {
Collect.getInstance()
.getActivityLogger()
.logInstanceAction(this, "onFling",
"showPrevious");
showPreviousView();
if (getSlidingMenu().isSecondaryMenuShowing()) {
toggleRigthMenu();
beenSwiped = false;
} else {
Collect.getInstance()
.getActivityLogger()
.logInstanceAction(this, "onFling",
"showPrevious");
showPreviousView();
}
}
} else {
if (e1.getX() < e2.getX()) {
Timber.e("showPreviousView VelocityX is bogus! %f < %f", e1.getX(), e2.getX());
Collect.getInstance()
.getActivityLogger()
.logInstanceAction(this, "onFling",
"showPrevious");
showPreviousView();
if (getSlidingMenu().isSecondaryMenuShowing()) {
toggleRigthMenu();
beenSwiped = false;
} else {
Timber.e("showPreviousView VelocityX is bogus! %f < %f", e1.getX(), e2.getX());
Collect.getInstance()
.getActivityLogger()
.logInstanceAction(this, "onFling",
"showPrevious");
showPreviousView();
}
} else {
Collect.getInstance().getActivityLogger()
.logInstanceAction(this, "onFling", "showNext");
showNextView(false);
if (getSlidingMenu().isMenuShowing()) {
toggleLeftMenu();
beenSwiped = false;
} else {
Collect.getInstance().getActivityLogger()
.logInstanceAction(this, "onFling", "showNext");
showNextView(false);
}
}
}
return true;
......
......@@ -72,7 +72,6 @@ public class SplashScreenActivity extends AppCompatActivity {
private static final boolean EXIT = true;
GeneralSharedPreferences preferences;
private SharedPreferences collectPreferences;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -80,8 +79,6 @@ public class SplashScreenActivity extends AppCompatActivity {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash_screen);
collectPreferences = getSharedPreferences(CapiInstancePreferences.COLLECTIVA_PREFERENCES_KEY,MODE_PRIVATE);
// get the shared preferences object
preferences = GeneralSharedPreferences.getInstance();
......
......@@ -68,9 +68,6 @@ public class Collect extends Application {
+ File.separator + "capi-stis";
public static final String FORMS_PATH = ODK_ROOT + File.separator + "forms";
public static final String INSTANCES_PATH = ODK_ROOT + File.separator + "instances";
public static final String INSTANCES_DOWNLOAD_PATH = ODK_ROOT + File.separator + "instances" + File.separator + "from aggregate";
public static final String INSTANCES_SAMPELTERPILIH_PATH = ODK_ROOT + File.separator + "instances" + File.separator + "sampel terpilih";
public static final String BRIEFCASE_PATH = ODK_ROOT + File.separator + "briefcase";
public static final String CACHE_PATH = ODK_ROOT + File.separator + ".cache";
public static final String METADATA_PATH = ODK_ROOT + File.separator + "metadata";
public static final String TMPFILE_PATH = CACHE_PATH + File.separator + "tmp.jpg";
......@@ -79,6 +76,11 @@ public class Collect extends Application {
public static final String DEFAULT_FONTSIZE = "16";
public static final String OFFLINE_LAYERS = ODK_ROOT + File.separator + "layers";
public static final String SETTINGS = ODK_ROOT + File.separator + "settings";
//modif CAPI
public static final String BRIEFCASE_PATH = ODK_ROOT + File.separator + "briefcase";
public static final String INSTANCES_DOWNLOAD_PATH = ODK_ROOT + File.separator + "instances" + File.separator + "from aggregate";
public static final String INSTANCES_SAMPELTERPILIH_PATH = ODK_ROOT + File.separator + "instances" + File.separator + "sampel terpilih";
private static Collect singleton = null;
static {
......@@ -121,7 +123,7 @@ public class Collect extends Application {
}
String[] dirs = {
ODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH, OFFLINE_LAYERS
ODK_ROOT, FORMS_PATH, INSTANCES_PATH, CACHE_PATH, METADATA_PATH, OFFLINE_LAYERS, BRIEFCASE_PATH
};
for (String dirName : dirs) {
......
......@@ -57,6 +57,7 @@ import org.odk.collect.android.dao.InstancesDao;
import org.odk.collect.android.dto.Instance;
import org.odk.collect.android.listeners.DeleteInstancesListener;
import org.odk.collect.android.listeners.DiskSyncListener;
import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.preferences.PreferenceKeys;
import org.odk.collect.android.provider.FormsProviderAPI;
import org.odk.collect.android.provider.InstanceProviderAPI;
......@@ -151,12 +152,17 @@ public class CapiInstanceActivity extends AppCompatActivity
recycleView.setLayoutManager(new LinearLayoutManager(this));
recycleView.setHasFixedSize(true);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fillBlankForm();
}
});
if (GeneralSharedPreferences.getInstance().get(PreferenceKeys.KEY_USERGROUP)
.toString().trim().equals("PML")) {
fab.setVisibility(View.GONE);
} else {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fillBlankForm();
}
});
}
instanceSyncTask = new InstanceSyncTask();
instanceSyncTask.setDiskSyncListener(this);
instanceSyncTask.execute();
......
......@@ -54,6 +54,10 @@ import static android.app.Activity.RESULT_OK;
public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapter.InstanceViewHolder>
implements Filterable {
public static final int MENU_UPLOAD = 0;
public static final int MENU_DELETE = 1;
private Activity context;
//list setelah filter
private List<CapiInstance> dataSet;
......@@ -61,13 +65,13 @@ public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapte
private List<CapiInstance> dataSetOri;
//nama form
private String formname = "";
//allow upload on selected item
private boolean allowUpload = true;
//callback menu select
public interface MenuListener{
void onMenuSelect(int mode, long[] instanceId);
}
public static final int MENU_UPLOAD = 0;
public static final int MENU_DELETE = 1;
private ArrayList<Integer> selectedItem = new ArrayList<>();
private MenuListener menuListener;
private ActionMode actionMode;
......@@ -88,6 +92,12 @@ public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapte
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()){
case R.id.action_upload:
if (!allowUpload) {
Toast.makeText(context, "Terdapat isian yang belum difinalisasi",
Toast.LENGTH_SHORT).show();
break;
}
long[] instancesId = getSelectedItemsId();
if (ArrayUtils.isNotEmpty(instancesId))
menuListener.onMenuSelect(MENU_UPLOAD, instancesId);
......@@ -148,7 +158,7 @@ public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapte
@Override
public InstanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
View v = LayoutInflater.from(context).inflate(R.layout.capi_item_instance, null);
View v = LayoutInflater.from(context).inflate(R.layout.capi_item_instance, parent, false);
return new InstanceViewHolder(v);
}
......@@ -217,13 +227,13 @@ public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapte
class InstanceViewHolder extends RecyclerView.ViewHolder
implements View.OnClickListener, View.OnLongClickListener {
TextView title, subtitle, status;
ImageView iconInstance, iconStatus, iconSelected;
LinearLayout statusHolder, holderDescription;
ImageView selection, btnEdit;
CardView cardView;
View divider;
String instanceStatus;
InstanceViewHolder(final View itemView) {
......@@ -425,18 +435,16 @@ public class CapiInstanceAdapter extends RecyclerView.Adapter<CapiInstanceAdapte
}
void selectItem(int layoutPosition){
boolean isSelected = selectedItem.contains(layoutPosition);
if (isSelected) selectedItem.remove(layoutPosition);
else selectedItem.add(layoutPosition);
//check instance finalized or fail to upload
if (!InstanceProviderAPI.STATUS_COMPLETE.equals(instanceStatus)
&& !InstanceProviderAPI.STATUS_SUBMISSION_FAILED.equals(instanceStatus)){
Toast.makeText(context, "Tidak dapat memilih form yang belum difinalisasi",
Toast.LENGTH_SHORT).show();
return;
allowUpload = isSelected;
}
boolean isSelected = selectedItem.contains(layoutPosition);
if (isSelected) selectedItem.remove(layoutPosition);
else selectedItem.add(layoutPosition);
if (selectedItem.size() == 0) actionMode.finish();
else {
actionMode.setTitle(selectedItem.size() + " isian terpilih");
......
......@@ -3,7 +3,6 @@ package org.odk.collect.android.capi.fragment;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.ConnectivityManager;
......
......@@ -94,7 +94,7 @@ public final class PreferenceKeys {
hashMap.put(KEY_ANALYTICS, true);
hashMap.put(KEY_INSTANCE_SYNC, true);
hashMap.put(KEY_APP_LANGUAGE, "");
hashMap.put(KEY_PROTOCOL, Collect.getInstance().getString(R.string.protocol_odk_default));
hashMap.put(KEY_PROTOCOL, Collect.getInstance().getString(R.string.protocol_odk_capi));
hashMap.put(KEY_SELECTED_GOOGLE_ACCOUNT, "");
hashMap.put(KEY_USERNAME, "");
hashMap.put(KEY_METADATA_USERNAME, "");
......@@ -103,7 +103,7 @@ public final class PreferenceKeys {
hashMap.put(KEY_SERVER_URL, Collect.getInstance().getString(R.string.default_server_url));
hashMap.put(KEY_GOOGLE_SHEETS_URL, "");
hashMap.put(KEY_FORMLIST_URL, Collect.getInstance().getString(R.string.default_odk_formlist));
hashMap.put(KEY_SUBMISSION_URL, Collect.getInstance().getString(R.string.default_odk_submission));
hashMap.put(KEY_SUBMISSION_URL, Collect.getInstance().getString(R.string.odk_capi_submit));
hashMap.put(KEY_NAVIGATION, "swipe");
hashMap.put(KEY_CONSTRAINT_BEHAVIOR, "on_swipe");
hashMap.put(KEY_COMPLETED_DEFAULT, true);
......
......@@ -453,10 +453,12 @@ public class InstanceProvider extends ContentProvider {
InstanceColumns.DISPLAY_SUBTEXT);
sInstancesProjectionMap.put(InstanceColumns.DELETED_DATE, InstanceColumns.DELETED_DATE);
//modifikasi CAPI-STIS
sInstancesProjectionMap.put(InstanceColumns.INSTANCE_UUID, InstanceColumns.INSTANCE_UUID);
sInstancesProjectionMap.put(InstanceColumns.NOTIF_DATA_UUID, InstanceColumns.NOTIF_DATA_UUID);
sInstancesProjectionMap.put(InstanceColumns.LATEST, InstanceColumns.LATEST);
sInstancesProjectionMap.put(InstanceColumns.LAST_UPDATE_DATE_SERVER, InstanceColumns.LAST_UPDATE_DATE_SERVER);
sInstancesProjectionMap.put(InstanceColumns.FROM_NOTIFICATION, InstanceColumns.FROM_NOTIFICATION);
}
}
......@@ -54,12 +54,12 @@ public class DataDownloadActivity extends AppCompatActivity
recyclerView.setAdapter(adapter);
setSupportActionBar(toolbar);
if (null != getSupportActionBar()){
getSupportActionBar().setTitle("Unduh Pembaruan");
getSupportActionBar().setTitle("Unduh Pengembalian");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
notifDataDao = new NotifDataDao();
cursorData = notifDataDao.getAdditinalCursor();
cursorData = notifDataDao.getNotifDataCursor();
adapter.changeCursor(cursorData);
}
......
......@@ -2,6 +2,7 @@ package org.odk.collect.android.revalidasi.adapter;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
......@@ -12,6 +13,8 @@ import android.widget.TextView;
import org.odk.collect.android.R;
import org.odk.collect.android.revalidasi.custom.NotifDataProviderAPI.NotifDataColumns;
import timber.log.Timber;
/**
* @author Mahendri Dwicahyo
*/
......@@ -45,7 +48,7 @@ public class DownAdapter extends RecyclerView.Adapter<DownAdapter.DownViewHolder
@Override
public void onBindViewHolder(DownAdapter.DownViewHolder holder, int position) {
if (!dataValid) throw new IllegalStateException("Cursor tidak valid");
cursor.moveToPosition(cursor.getPosition());
cursor.moveToPosition(position);
holder.setData(cursor);
}
......
......@@ -25,7 +25,7 @@ public class NotifDataDao {
String selectionArgs[] = {values.get(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID).toString(),
values.get(NotifDataProviderAPI.NotifDataColumns.LAST_UPDATE_DATE).toString()};
Cursor lebih = getAdditinalCursor(selection, selectionArgs);
Cursor lebih = getNotifDataCursor(selection, selectionArgs);
if(lebih.getCount()==0){
lebih.close();
String selection2 = NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID + " =? and " +
......@@ -51,14 +51,14 @@ public class NotifDataDao {
}
//edit Mahendri
public Cursor getAdditinalCursor() {
public Cursor getNotifDataCursor() {
String selection = NotifDataColumns.LATEST + " =? ";
String[] selectionArgs = new String[]{String.valueOf(NotifDataColumns.IS_LATEST)};
return getNotifDataCursor(null, selection, selectionArgs, null);
}
public Cursor getAdditinalCursor(CharSequence charSequence,String sortOrder, boolean viewMode) {
public Cursor getNotifDataCursor(CharSequence charSequence, String sortOrder, boolean viewMode) {
if(viewMode){
String selection = NotifDataProviderAPI.NotifDataColumns.NAME_INSTANCE + " LIKE ? and "
+ NotifDataProviderAPI.NotifDataColumns.LATEST+ " =? ";
......@@ -77,11 +77,11 @@ public class NotifDataDao {
}
}
public Cursor getAdditinalCursor(String sortOrder) {
public Cursor getNotifDataCursor(String sortOrder) {
return getNotifDataCursor(null, null, null, sortOrder);
}
public Cursor getAdditinalCursor(String selection, String[] selectionArgs) {
public Cursor getNotifDataCursor(String selection, String[] selectionArgs) {
return getNotifDataCursor(null, selection, selectionArgs, null);
}
......@@ -196,7 +196,7 @@ public class NotifDataDao {
return notifDataList;
}
public ContentValues getValuesFromAdditinalObject(NotifData notifData) {
public ContentValues getValuesFromNotifData(NotifData notifData) {
ContentValues values = new ContentValues();
values.put(NotifDataProviderAPI.NotifDataColumns.UUID, notifData.getUuid());
values.put(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID, notifData.getInstanceuuid());
......
......@@ -249,10 +249,10 @@ public class NotifDataProvider extends ContentProvider {
static {
sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sUriMatcher.addURI(NotifDataProviderAPI.AUTHORITY, "additional", ADDITIONAL);
sUriMatcher.addURI(NotifDataProviderAPI.AUTHORITY, "additional/#", ADDITIONAL_ID);
sUriMatcher.addURI(NotifDataProviderAPI.AUTHORITY, "notifdata", ADDITIONAL);
sUriMatcher.addURI(NotifDataProviderAPI.AUTHORITY, "notifdata/#", ADDITIONAL_ID);
sAdditionalProjectionMap = new HashMap<String, String>();
sAdditionalProjectionMap = new HashMap<>();
sAdditionalProjectionMap.put(NotifDataProviderAPI.NotifDataColumns._ID, NotifDataProviderAPI.NotifDataColumns._ID);
sAdditionalProjectionMap.put(NotifDataProviderAPI.NotifDataColumns.UUID, NotifDataProviderAPI.NotifDataColumns.UUID);
sAdditionalProjectionMap.put(NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID, NotifDataProviderAPI.NotifDataColumns.INSTANCE_UUID);
......
package org.odk.collect.android.revalidasi.notifikasi;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import com.google.firebase.messaging.FirebaseMessaging;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.preferences.GeneralSharedPreferences;
import org.odk.collect.android.preferences.PreferenceKeys;
import org.odk.collect.android.revalidasi.briefcase.util.WebUtils;
import org.odk.collect.android.utilities.WebUtils;
import org.opendatakit.httpclientandroidlib.HttpEntity;
import org.opendatakit.httpclientandroidlib.HttpRequest;
import org.opendatakit.httpclientandroidlib.HttpResponse;
import org.opendatakit.httpclientandroidlib.HttpStatus;
import org.opendatakit.httpclientandroidlib.auth.AuthScope;
import org.opendatakit.httpclientandroidlib.auth.Credentials;
import org.opendatakit.httpclientandroidlib.auth.UsernamePasswordCredentials;
import org.opendatakit.httpclientandroidlib.client.CookieStore;
import org.opendatakit.httpclientandroidlib.client.CredentialsProvider;
import org.opendatakit.httpclientandroidlib.client.HttpClient;
import org.opendatakit.httpclientandroidlib.client.config.AuthSchemes;
import org.opendatakit.httpclientandroidlib.client.config.RequestConfig;
import org.opendatakit.httpclientandroidlib.client.methods.HttpGet;
import org.opendatakit.httpclientandroidlib.client.methods.HttpPost;
import org.opendatakit.httpclientandroidlib.client.protocol.HttpClientContext;
import org.opendatakit.httpclientandroidlib.client.utils.DateUtils;
import org.opendatakit.httpclientandroidlib.config.SocketConfig;
import org.opendatakit.httpclientandroidlib.impl.client.BasicCookieStore;
import org.opendatakit.httpclientandroidlib.impl.client.BasicCredentialsProvider;
import org.opendatakit.httpclientandroidlib.impl.client.HttpClientBuilder;
import org.opendatakit.httpclientandroidlib.protocol.HttpContext;
import org.opendatakit.httpclientandroidlib.util.EntityUtils;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import timber.log.Timber;
......@@ -95,16 +70,18 @@ public class GetUuidTask extends AsyncTask<String, String, String> {
}
// get shared HttpContext so that authentication and cookies are retained.
HttpClientContext localContext = WebUtils.createHttpContext();
HttpClient httpclient = WebUtils.createHttpClient();
HttpContext localContext = Collect.getInstance().getHttpContext();
HttpClient httpclient = WebUtils.createHttpClient(WebUtils.CONNECTION_TIMEOUT);
// set up request...
HttpGet req = WebUtils.createOpenRosaHttpGet(loginUri);
WebUtils.clearAllCredentials(localContext);
String host = loginUri == null? null : loginUri.getHost();
System.out.println(host);
WebUtils.addCredentials(localContext, username, password.toCharArray(), host);
//add credentials
WebUtils.clearAllCredentials();
WebUtils.addCredentials(username, password, host);
Timber.d("username: %s, password: %s", username, password);
HttpResponse response;
......@@ -151,8 +128,6 @@ public class GetUuidTask extends AsyncTask<String, String, String> {
if(StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().subscribeToTopic(getPureUri(uuid));
clearCachedCrendentials();
Timber.d("AggregatePreference UUID2: %s", uuid);
return "Sukses login server";
......@@ -167,12 +142,4 @@ public class GetUuidTask extends AsyncTask<String, String, String> {
.replaceAll("\\:","")
.replaceAll("\\|","");
}
private void clearCachedCrendentials() {
String server = (String) GeneralSharedPreferences
.getInstance().get(PreferenceKeys.KEY_SERVER_URL);
Uri u = Uri.parse(server);
org.odk.collect.android.utilities.WebUtils.clearHostCredentials(u.getHost());
Collect.getInstance().getCookieStore().clear();
}
}
......@@ -3,6 +3,7 @@ package org.odk.collect.android.revalidasi.notifikasi;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
......@@ -15,9 +16,10 @@ import org.odk.collect.android.revalidasi.activities.DataDownloadActivity;
import org.odk.collect.android.revalidasi.custom.NotifData;
import org.odk.collect.android.revalidasi.custom.NotifDataDao;
import java.util.Date;
import java.util.UUID;
import timber.log.Timber;
/**
* @author Budi Setiawan Akkas
*/
......@@ -31,9 +33,6 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "Notification Body: " + remoteMessage.getNotification().getBody());
......@@ -49,7 +48,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
JSONObject jsonObject = new JSONObject();
jsonObject.put("PrimaryLine", remoteMessage.getData().get("PrimaryLine"));
jsonObject.put("SecondaryLine", remoteMessage.getData().get("SecondaryLine"));
JSONObject attach = new JSONObject(remoteMessage.getData().get("attachData").toString());
JSONObject attach = new JSONObject(remoteMessage.getData().get("attachData"));
jsonObject.put("attachData",attach);
Log.e(TAG, "Data json: " + jsonObject.toString());
handleDataMessage(jsonObject);
......@@ -65,12 +64,9 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
Intent pushNotification = new Intent(ConfigKey.PUSH_NOTIFICATION);
pushNotification.putExtra("message", message);
LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
// play notification sound
NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.playNotificationSound();
}else{
// If the app is in background, firebase itself handles the notification
Timber.i("app in background, firebase handle");
}
}
......@@ -78,7 +74,6 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
Log.e(TAG, "push json: " + data.toString());
try {
//JSONObject data = json.getJSONObject("data");
String title = data.getString("PrimaryLine");
String message = data.getString("SecondaryLine");
......@@ -110,12 +105,9 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
JSONObject mAttachData = payload.getJSONObject("ATTACH_DATA");
String mNameInstance = payload.getString("NAME_INSTANCE");
Log.e(TAG, "title: " + title);
Log.e(TAG, "message: " + message);
//Log.e(TAG, "isBackground: " + isBackground);
Log.e(TAG, "payload: " + payload.toString());
//Log.e(TAG, "imageUrl: " + imageUrl);
//Log.e(TAG, "timestamp: " + timestamp);
Timber.e(TAG, "title: " + title);
Timber.e(TAG, "message: " + message);
Timber.e(TAG, "payload: " + payload.toString());
NotifData notifData = new NotifData.Builder()
.uuid(mUuid)
......@@ -139,32 +131,15 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
.latest("1")
.download("0")
.build();
ContentValues values = (new NotifDataDao()).getValuesFromAdditinalObject(notifData);
(new NotifDataDao()).saveInstance(values);
ContentValues values = (new NotifDataDao()).getValuesFromNotifData(notifData);
Uri insert = (new NotifDataDao()).saveInstance(values);
Timber.i("Insert on %s", insert.toString());
}
Intent resultIntent = new Intent(getApplicationContext(), DataDownloadActivity.class);
resultIntent.putExtra("message", message);
// check for image attachmen
showNotificationMessage(getApplicationContext(), title, message, (new Date()).toString(), resultIntent);
notificationUtils.playNotificationSound();
// if (!NotificationUtils.isAppIsInBackground(getApplicationContext())) {
// // app is in foreground, broadcast the push message
// Intent pushNotification = new Intent(ConfigKey.PUSH_NOTIFICATION);
// pushNotification.putExtra("message", message);
// LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);
//
// // play notification sound
// NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
// notificationUtils.playNotificationSound();
// } else {
// // app is in background, show the notification in notification tray
// Intent resultIntent = new Intent(getApplicationContext(), DataDownloadActivity.class);
// resultIntent.putExtra("message", message);
// // check for image attachmen
// showNotificationMessage(getApplicationContext(), title, message, (new Date()).toString(), resultIntent);
//
// }
// check for image attachment
showNotificationMessage(getApplicationContext(), title, message, System.currentTimeMillis(), resultIntent);
} catch (JSONException e) {
Log.e(TAG, "Json Exception: " + e.getMessage());
} catch (Exception e) {
......@@ -175,18 +150,9 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
/**
* Showing notification with text only
*/
private void showNotificationMessage(Context context, String title, String message, String timeStamp, Intent intent) {
private void showNotificationMessage(Context context, String title, String message, long timeStamp, Intent intent) {
notificationUtils = new NotificationUtils(context);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationUtils.showNotificationMessage(title, message, timeStamp, intent);
}
/**
* Showing notification with text and image
*/
private void showNotificationMessageWithBigImage(Context context, String title, String message, String timeStamp, Intent intent, String imageUrl) {
notificationUtils = new NotificationUtils(context);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationUtils.showNotificationMessage(title, message, timeStamp, intent, imageUrl);
}
}
\ No newline at end of file
package org.odk.collect.android.revalidasi.notifikasi;
// Edited by Budi Setiawan Akkas
import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.text.Html;
import android.text.TextUtils;
import android.util.Patterns;
import org.odk.collect.android.R;