Refactored to lambda expressions and fixe some minor bugs
This commit is contained in:
@@ -98,13 +98,13 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-apk" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-main-apk-res" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-main-apk-res" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged-not-compiled-resources" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged-not-compiled-resources" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/prebuild" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/processing-tools" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ android {
|
|||||||
applicationId "org.deke.risk.riskahead"
|
applicationId "org.deke.risk.riskahead"
|
||||||
minSdkVersion 19
|
minSdkVersion 19
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 48
|
versionCode 49
|
||||||
versionName "3.1.4"
|
versionName "3.1.5"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
|||||||
Binary file not shown.
@@ -1 +1 @@
|
|||||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":48,"versionName":"3.1.4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":49,"versionName":"3.1.5","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
|
||||||
@@ -3,14 +3,11 @@ package org.deke.risk.riskahead;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.support.design.widget.TextInputLayout;
|
import android.support.design.widget.TextInputLayout;
|
||||||
import android.support.v4.app.FragmentManager;
|
|
||||||
import android.support.v4.app.FragmentTransaction;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -23,7 +20,6 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -40,8 +36,6 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import com.android.volley.Request.Method;
|
import com.android.volley.Request.Method;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
@@ -95,7 +89,6 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void isNetworkAvailable() {
|
public void isNetworkAvailable() {
|
||||||
@@ -113,10 +106,8 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
.setTitle(getString(R.string.alert_internetconnection_title))
|
.setTitle(getString(R.string.alert_internetconnection_title))
|
||||||
.setMessage(getString(R.string.alert_internetconnection_text))
|
.setMessage(getString(R.string.alert_internetconnection_text))
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setNeutralButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setNeutralButton(android.R.string.yes, (dialog, which) -> {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
//todo What to do when no internet connection is available?
|
||||||
//todo What to do when no internet connection is available?
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
@@ -152,18 +143,10 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
TextView btn_requestPW = findViewById(R.id.lbl_login_resendPW);
|
TextView btn_requestPW = findViewById(R.id.lbl_login_resendPW);
|
||||||
|
|
||||||
BootstrapButton btn_gotoregistration = findViewById(R.id.btn_switchtoregistration);
|
BootstrapButton btn_gotoregistration = findViewById(R.id.btn_switchtoregistration);
|
||||||
btn_gotoregistration.setOnClickListener(new View.OnClickListener() {
|
btn_gotoregistration.setOnClickListener(this::gotoRegister);
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
gotoRegister(v);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
BootstrapButton btn_login = findViewById(R.id.btn_login);
|
BootstrapButton btn_login = findViewById(R.id.btn_login);
|
||||||
btn_login.setOnClickListener(new View.OnClickListener() {
|
btn_login.setOnClickListener((View v) -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
|
|
||||||
String email = input_email.getText().toString();
|
String email = input_email.getText().toString();
|
||||||
String password = input_password.getText().toString();
|
String password = input_password.getText().toString();
|
||||||
|
|
||||||
@@ -173,7 +156,6 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
showDialog();
|
showDialog();
|
||||||
performLogin(email, password);
|
performLogin(email, password);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
input_email.addTextChangedListener(new TextValidator(input_email, inputLayoutEmail, getApplicationContext()) {
|
input_email.addTextChangedListener(new TextValidator(input_email, inputLayoutEmail, getApplicationContext()) {
|
||||||
@@ -198,12 +180,7 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btn_requestPW.setOnClickListener(new View.OnClickListener() {
|
btn_requestPW.setOnClickListener(this::onRequestNewPasswordClick);
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
onRequestNewPasswordClick(v);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initRegisterView() {
|
private void initRegisterView() {
|
||||||
@@ -251,38 +228,25 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btn_login.setOnClickListener(new View.OnClickListener() {
|
btn_login.setOnClickListener(v -> {
|
||||||
@Override
|
String email = input_email.getText().toString();
|
||||||
public void onClick(View v) {
|
String password = input_password.getText().toString();
|
||||||
String email = input_email.getText().toString();
|
|
||||||
String password = input_password.getText().toString();
|
|
||||||
|
|
||||||
String name = input_username.getText().toString();
|
String name = input_username.getText().toString();
|
||||||
if (inputLayoutPassword.getError() != null || inputLayoutEmail.getError() != null || inputLayoutUsername.getError() != null || input_email.getText().toString().trim().length() == 0 || input_username.getText().toString().trim().length() == 0 || input_password.getText().toString().trim().length() == 0) {
|
if (inputLayoutPassword.getError() != null || inputLayoutEmail.getError() != null || inputLayoutUsername.getError() != null || input_email.getText().toString().trim().length() == 0 || input_username.getText().toString().trim().length() == 0 || input_password.getText().toString().trim().length() == 0) {
|
||||||
showMessage(getString(R.string.error_validation));
|
showMessage(getString(R.string.error_validation));
|
||||||
} else {
|
} else {
|
||||||
showDialog();
|
showDialog();
|
||||||
checkForUserAndPerformRegistration(name, email, password);
|
checkForUserAndPerformRegistration(name, email, password);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btn_switchtologin.setOnClickListener(new View.OnClickListener() {
|
btn_switchtologin.setOnClickListener(this::gotoLogin);
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
gotoLogin(v);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSocialLoginButtons() {
|
private void initSocialLoginButtons() {
|
||||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
|
||||||
new FacebookButtonFragment();
|
new FacebookButtonFragment();
|
||||||
GooglePlusButtonFragment fragmentGP = new GooglePlusButtonFragment();
|
new GooglePlusButtonFragment();
|
||||||
|
|
||||||
FragmentTransaction transaction = fragmentManager.beginTransaction();
|
|
||||||
transaction.add(R.id.frag_login_btnGP, fragmentGP);
|
|
||||||
transaction.commit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForMaintenance() {
|
private void checkForMaintenance() {
|
||||||
@@ -292,32 +256,24 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestCheckForMaintenance() {
|
private StringRequest getStringRequestCheckForMaintenance() {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_CHECK_MAINTENANCE, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_CHECK_MAINTENANCE, response -> {
|
||||||
|
Log.d(TAG, "Check for Maintenance Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Check for Maintenance Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
if(jObj.getBoolean("maintenancemode")){
|
||||||
boolean error = jObj.getBoolean("error");
|
showMessage(jObj.getString("maintenancemsg"));
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
if(jObj.getBoolean("maintenancemode")){
|
|
||||||
showMessage(jObj.getString("maintenancemsg"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -346,34 +302,26 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestCheckIfVersionSupported() {
|
private StringRequest getStringRequestCheckIfVersionSupported() {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_CHECK_VERSION, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_CHECK_VERSION, response -> {
|
||||||
|
Log.d(TAG, "Check Version Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Check Version Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
if(!jObj.getBoolean("supported")){
|
||||||
boolean error = jObj.getBoolean("error");
|
showNotSupportedDialog();
|
||||||
|
}else if(!jObj.getBoolean("recommended")){
|
||||||
if (!error) {
|
showNotRecommendDialog();
|
||||||
if(!jObj.getBoolean("supported")){
|
|
||||||
showNotSupportedDialog();
|
|
||||||
}else if(!jObj.getBoolean("recommended")){
|
|
||||||
showNotRecommendDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -399,18 +347,12 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
.setTitle(getString(R.string.alert_notsupported_title))
|
.setTitle(getString(R.string.alert_notsupported_title))
|
||||||
.setMessage(getString(R.string.alert_notsupported_text))
|
.setMessage(getString(R.string.alert_notsupported_text))
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.update, (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()))))
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setNegativeButton(R.string.exit, (dialog, which) -> {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
}
|
intent.addCategory(Intent.CATEGORY_HOME);
|
||||||
})
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
|
startActivity(intent);
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.addCategory(Intent.CATEGORY_HOME);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
@@ -421,15 +363,9 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
.setTitle(getString(R.string.alert_notrecommended_title))
|
.setTitle(getString(R.string.alert_notrecommended_title))
|
||||||
.setMessage(getString(R.string.alert_notrecommended_text))
|
.setMessage(getString(R.string.alert_notrecommended_text))
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.update, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.update, (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName()))))
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setNegativeButton(R.string.later, (dialog, which) -> {
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.later, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
@@ -480,15 +416,9 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
new AlertDialog.Builder(LoginActivity.this)
|
new AlertDialog.Builder(LoginActivity.this)
|
||||||
.setTitle(getString(R.string.alert_passwordreset_title))
|
.setTitle(getString(R.string.alert_passwordreset_title))
|
||||||
.setMessage(getString(R.string.alert_passwordreset_text))
|
.setMessage(getString(R.string.alert_passwordreset_text))
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> performRequestNewPassword())
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
performRequestNewPassword();
|
// do nothing
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
@@ -507,75 +437,67 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestSocialMediaLogin(final String key, final String providerType, final String username, final String email) {
|
private StringRequest getStringRequestSocialMediaLogin(final String key, final String providerType, final String username, final String email) {
|
||||||
return new StringRequest(Method.POST,AppConfig.REST_LOGIN_SOCIAL, new Response.Listener<String>() {
|
return new StringRequest(Method.POST,AppConfig.REST_LOGIN_SOCIAL, response -> {
|
||||||
|
Log.d(TAG, "Social Media Login Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Social Media Login Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
if (!error) {
|
||||||
|
session.setLogin(true);
|
||||||
|
|
||||||
try {
|
JSONObject user = jObj.getJSONObject("user");
|
||||||
JSONObject jObj = new JSONObject(response);
|
String id = user.getString("id");
|
||||||
boolean error = jObj.getBoolean("error");
|
String username1 = user.getString("username");
|
||||||
if (!error) {
|
String name = user.getString("name");
|
||||||
session.setLogin(true);
|
String surname = user.getString("surname");
|
||||||
|
String email1 = user.getString("email");
|
||||||
|
String status = user.getString("status");
|
||||||
|
String created_at = user.getString("created_at");
|
||||||
|
String updated_at = user.getString("updated_at");
|
||||||
|
String lastlogin_at = user.getString("lastlogin_at");
|
||||||
|
String providerType1 = user.getString("providerType");
|
||||||
|
String token = user.getString("accesskey");
|
||||||
|
|
||||||
JSONObject user = jObj.getJSONObject("user");
|
JSONArray jSubs = user.getJSONArray("subs");
|
||||||
String id = user.getString("id");
|
boolean isPremium = false;
|
||||||
String username = user.getString("username");
|
boolean isAdFree = false;
|
||||||
String name = user.getString("name");
|
|
||||||
String surname = user.getString("surname");
|
|
||||||
String email = user.getString("email");
|
|
||||||
String status = user.getString("status");
|
|
||||||
String created_at = user.getString("created_at");
|
|
||||||
String updated_at = user.getString("updated_at");
|
|
||||||
String lastlogin_at = user.getString("lastlogin_at");
|
|
||||||
String providerType = user.getString("providerType");
|
|
||||||
String token = user.getString("accesskey");
|
|
||||||
|
|
||||||
JSONArray jSubs = user.getJSONArray("subs");
|
if(jSubs.length() > 0){
|
||||||
boolean isPremium = false;
|
for(int i = 0; i < jSubs.length();i++) {
|
||||||
boolean isAdFree = false;
|
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
||||||
|
isPremium = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(jSubs.length() > 0){
|
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
||||||
for(int i = 0; i < jSubs.length();i++) {
|
isAdFree = true;
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
|
||||||
isPremium = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
|
||||||
isAdFree = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.addUser(id, username, name, surname, email, status, providerType, created_at, updated_at, lastlogin_at, token,isPremium,isAdFree);
|
|
||||||
|
|
||||||
Intent intent = new Intent(
|
|
||||||
LoginActivity.this,
|
|
||||||
MapsActivity.class);
|
|
||||||
intent.putExtra(AppConfig.EXTRA_MESSAGE, AppConfig.INTENT_SOCIALMEDIALOGIN);
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error at social media login (Server returned error): " + errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login)+getResources().getString(R.string.txt_errormsg_suffix), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
session.addUser(id, username1, name, surname, email1, status, providerType1, created_at, updated_at, lastlogin_at, token,isPremium,isAdFree);
|
||||||
Crashlytics.logException(e);
|
|
||||||
|
Intent intent = new Intent(
|
||||||
|
LoginActivity.this,
|
||||||
|
MapsActivity.class);
|
||||||
|
intent.putExtra(AppConfig.EXTRA_MESSAGE, AppConfig.INTENT_SOCIALMEDIALOGIN);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error at social media login (Server returned error): " + errorMsg);
|
||||||
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login)+getResources().getString(R.string.txt_errormsg_suffix), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
}, error -> {
|
||||||
public void onErrorResponse(VolleyError error) {
|
Crashlytics.log(Log.ERROR, TAG, "Social Media Login Error: " + error.getMessage());
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Social Media Login Error: " + error.getMessage());
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login)+getResources().getString(R.string.txt_errormsg_suffix), Toast.LENGTH_LONG).show();
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login)+getResources().getString(R.string.txt_errormsg_suffix), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -593,95 +515,83 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestLogin(final String email, final String password) {
|
private StringRequest getStringRequestLogin(final String email, final String password) {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_LOGIN, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_LOGIN, response -> {
|
||||||
|
Log.d(TAG, "Login Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Login Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject user = jObj.getJSONObject("user");
|
||||||
boolean error = jObj.getBoolean("error");
|
String id = user.getString("id");
|
||||||
|
String username = user.getString("username");
|
||||||
|
String name = user.getString("name");
|
||||||
|
String surname = user.getString("surname");
|
||||||
|
String email1 = user.getString("email");
|
||||||
|
String status = user.getString("status");
|
||||||
|
String created_at = user.getString("created_at");
|
||||||
|
String updated_at = user.getString("updated_at");
|
||||||
|
String lastlogin_at = user.getString("lastlogin_at");
|
||||||
|
String token = user.getString("accesskey");
|
||||||
|
String providerType = "local";
|
||||||
|
|
||||||
if (!error) {
|
JSONArray jSubs = user.getJSONArray("subs");
|
||||||
JSONObject user = jObj.getJSONObject("user");
|
boolean isPremium = false;
|
||||||
String id = user.getString("id");
|
boolean isAdFree = false;
|
||||||
String username = user.getString("username");
|
|
||||||
String name = user.getString("name");
|
|
||||||
String surname = user.getString("surname");
|
|
||||||
String email = user.getString("email");
|
|
||||||
String status = user.getString("status");
|
|
||||||
String created_at = user.getString("created_at");
|
|
||||||
String updated_at = user.getString("updated_at");
|
|
||||||
String lastlogin_at = user.getString("lastlogin_at");
|
|
||||||
String token = user.getString("accesskey");
|
|
||||||
String providerType = "local";
|
|
||||||
|
|
||||||
JSONArray jSubs = user.getJSONArray("subs");
|
if(jSubs.length() > 0){
|
||||||
boolean isPremium = false;
|
for(int i = 0; i < jSubs.length();i++) {
|
||||||
boolean isAdFree = false;
|
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
||||||
|
isPremium = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(jSubs.length() > 0){
|
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
||||||
for(int i = 0; i < jSubs.length();i++) {
|
isAdFree = true;
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
|
||||||
isPremium = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
|
||||||
isAdFree = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(status.equals("0")){
|
|
||||||
new AlertDialog.Builder(LoginActivity.this)
|
|
||||||
.setTitle(getString(R.string.alert_accactivation_title))
|
|
||||||
.setMessage(getString(R.string.alert_accactivation_text))
|
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
String tag_string_req = "resendactivationusermail";
|
|
||||||
|
|
||||||
StringRequest strReq = getStringRequestActivationLinkUser(input_email.getText().toString());
|
|
||||||
|
|
||||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
|
||||||
showMessage(getString(R.string.alert_accactivation_confirmation));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
||||||
.show();
|
|
||||||
}else {
|
|
||||||
session.addUser(id, username, name, surname, email, status, providerType, created_at, updated_at, lastlogin_at, token, isPremium, isAdFree);
|
|
||||||
session.setLogin(true);
|
|
||||||
|
|
||||||
hideDialog();
|
|
||||||
|
|
||||||
Intent intent = new Intent(LoginActivity.this, MapsActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error at login (Server returned error): " + errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
if(status.equals("0")){
|
||||||
public void onErrorResponse(VolleyError error) {
|
new AlertDialog.Builder(LoginActivity.this)
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Login Error: " + error.getMessage());
|
.setTitle(getString(R.string.alert_accactivation_title))
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login), Toast.LENGTH_LONG).show();
|
.setMessage(getString(R.string.alert_accactivation_text))
|
||||||
hideDialog();
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||||
|
String tag_string_req = "resendactivationusermail";
|
||||||
|
|
||||||
|
StringRequest strReq = getStringRequestActivationLinkUser(input_email.getText().toString());
|
||||||
|
|
||||||
|
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||||
|
showMessage(getString(R.string.alert_accactivation_confirmation));
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
|
})
|
||||||
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.show();
|
||||||
|
}else {
|
||||||
|
session.addUser(id, username, name, surname, email1, status, providerType, created_at, updated_at, lastlogin_at, token, isPremium, isAdFree);
|
||||||
|
session.setLogin(true);
|
||||||
|
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
|
Intent intent = new Intent(LoginActivity.this, MapsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error at login (Server returned error): " + errorMsg);
|
||||||
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Login Error: " + error.getMessage());
|
||||||
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_login), Toast.LENGTH_LONG).show();
|
||||||
|
hideDialog();
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -696,46 +606,38 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestCheckUserExists(final String username, final String email, final String password) {
|
private StringRequest getStringRequestCheckUserExists(final String username, final String email, final String password) {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_USEREXISTS, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_USEREXISTS, response -> {
|
||||||
|
Log.d(TAG, "Check User Exists Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Check User Exists Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
if (!error) {
|
||||||
|
|
||||||
try {
|
if(jObj.getInt("exists") == 1){
|
||||||
JSONObject jObj = new JSONObject(response);
|
showMessage("Registration failed. Username and/or E-Mail already taken");
|
||||||
boolean error = jObj.getBoolean("error");
|
}else{
|
||||||
if (!error) {
|
createAndShowPrivacyDialog(username, email, password);
|
||||||
|
|
||||||
if(jObj.getInt("exists") == 1){
|
|
||||||
showMessage("Registration failed. Username and/or E-Mail already taken");
|
|
||||||
}else{
|
|
||||||
createAndShowPrivacyDialog(username, email, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error occured: "+errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Exception caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Registration Error: " + error.getMessage());
|
} else {
|
||||||
Toast.makeText(getApplicationContext(),
|
String errorMsg = jObj.getString("error_msg");
|
||||||
getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
Crashlytics.log(Log.ERROR, TAG, "Error occured: "+errorMsg);
|
||||||
hideDialog();
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}) {
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Exception caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Registration Error: " + error.getMessage());
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
||||||
|
hideDialog();
|
||||||
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
@@ -748,43 +650,35 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestCheckSocialUserExists(final String key, final String providerType, final String username, final String email) {
|
private StringRequest getStringRequestCheckSocialUserExists(final String key, final String providerType, final String username, final String email) {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_USEREXISTS, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_USEREXISTS, response -> {
|
||||||
|
Log.d(TAG, "Check Social User Exists Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Check Social User Exists Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
if (!error) {
|
||||||
|
|
||||||
try {
|
if(jObj.getInt("exists") == 1){
|
||||||
JSONObject jObj = new JSONObject(response);
|
performSocialMediaLogin( key,providerType, username, email);
|
||||||
boolean error = jObj.getBoolean("error");
|
}else{
|
||||||
if (!error) {
|
createAndShowPrivacyDialogForSocialUser( key,providerType, username, email);
|
||||||
|
|
||||||
if(jObj.getInt("exists") == 1){
|
|
||||||
performSocialMediaLogin( key,providerType, username, email);
|
|
||||||
}else{
|
|
||||||
createAndShowPrivacyDialogForSocialUser( key,providerType, username, email);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error occured: "+errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
} else {
|
||||||
public void onErrorResponse(VolleyError error) {
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Registration Error: " + error.getMessage());
|
Crashlytics.log(Log.ERROR, TAG, "Error occured: "+errorMsg);
|
||||||
Toast.makeText(getApplicationContext(),
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
||||||
getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
}
|
||||||
hideDialog();
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Registration Error: " + error.getMessage());
|
||||||
|
Toast.makeText(getApplicationContext(),
|
||||||
|
getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
||||||
|
hideDialog();
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -827,27 +721,18 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this)
|
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this)
|
||||||
.setTitle(R.string.txt_register_privacy_title)
|
.setTitle(R.string.txt_register_privacy_title)
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> performSocialMediaLogin(key, providerType, username, email))
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
performSocialMediaLogin(key, providerType, username, email);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(R.drawable.logo_380);
|
.setIcon(R.drawable.logo_380);
|
||||||
|
|
||||||
final AlertDialog dialog = builder.create();
|
final AlertDialog dialog = builder.create();
|
||||||
|
|
||||||
privacyCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
privacyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
@Override
|
if (isChecked) {
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||||
if (isChecked) {
|
} else {
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||||
} else {
|
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -888,27 +773,18 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this)
|
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this)
|
||||||
.setTitle(R.string.txt_register_privacy_title)
|
.setTitle(R.string.txt_register_privacy_title)
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> performRegistration(username, email, password))
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
performRegistration(username, email, password);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(R.drawable.logo_380);
|
.setIcon(R.drawable.logo_380);
|
||||||
|
|
||||||
final AlertDialog dialog = builder.create();
|
final AlertDialog dialog = builder.create();
|
||||||
|
|
||||||
privacyCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
privacyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
@Override
|
if (isChecked) {
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||||
if (isChecked) {
|
} else {
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||||
} else {
|
|
||||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -919,39 +795,31 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestResetPW(final String email) {
|
private StringRequest getStringRequestResetPW(final String email) {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_REQUESTPWRESET, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_REQUESTPWRESET, response -> {
|
||||||
|
Log.d(TAG, "Resend E-Mail Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Resend E-Mail Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
if (!error) {
|
||||||
|
showMessage(getString(R.string.alert_passwordreset_confirmation));
|
||||||
try {
|
} else {
|
||||||
JSONObject jObj = new JSONObject(response);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
Crashlytics.log(Log.ERROR, TAG, "Reset PW returned error value: "+errorMsg);
|
||||||
if (!error) {
|
Toast.makeText(getApplicationContext(),
|
||||||
showMessage(getString(R.string.alert_passwordreset_confirmation));
|
getResources().getString(R.string.txt_errormsg_getpwreset), Toast.LENGTH_LONG).show();
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Reset PW returned error value: "+errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
getResources().getString(R.string.txt_errormsg_getpwreset), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
}, error -> {
|
||||||
public void onErrorResponse(VolleyError error) {
|
Crashlytics.log(Log.ERROR, TAG, "E-Mail pw resend Error: " + error.getMessage());
|
||||||
Crashlytics.log(Log.ERROR, TAG, "E-Mail pw resend Error: " + error.getMessage());
|
Toast.makeText(getApplicationContext(),
|
||||||
Toast.makeText(getApplicationContext(),
|
getResources().getString(R.string.txt_errormsg_getpwreset), Toast.LENGTH_LONG).show();
|
||||||
getResources().getString(R.string.txt_errormsg_getpwreset), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -965,37 +833,29 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestActivationLinkUser(final String email) {
|
private StringRequest getStringRequestActivationLinkUser(final String email) {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_SENDACTIVATIONMAIL, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_SENDACTIVATIONMAIL, response -> {
|
||||||
|
Log.d(TAG, "Resend E-Mail Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Resend E-Mail Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
if (error) {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
try {
|
Crashlytics.log(Log.ERROR, TAG,"Resend E-Mail returned error value: "+errorMsg);
|
||||||
JSONObject jObj = new JSONObject(response);
|
Toast.makeText(getApplicationContext(),
|
||||||
boolean error = jObj.getBoolean("error");
|
getResources().getString(R.string.txt_errormsg_getactivationlink) + ":"+errorMsg, Toast.LENGTH_LONG).show();
|
||||||
if (error) {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG,"Resend E-Mail returned error value: "+errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
getResources().getString(R.string.txt_errormsg_getactivationlink) + ":"+errorMsg, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
}, error -> {
|
||||||
public void onErrorResponse(VolleyError error) {
|
Crashlytics.log(Log.ERROR, TAG, "E-Mail pw resend error: " + error.getMessage());
|
||||||
Crashlytics.log(Log.ERROR, TAG, "E-Mail pw resend error: " + error.getMessage());
|
Toast.makeText(getApplicationContext(),
|
||||||
Toast.makeText(getApplicationContext(),
|
getResources().getString(R.string.txt_errormsg_getactivationlink), Toast.LENGTH_LONG).show();
|
||||||
getResources().getString(R.string.txt_errormsg_getactivationlink), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1009,51 +869,41 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestRegisterUser(final String username, final String email, final String password) {
|
private StringRequest getStringRequestRegisterUser(final String username, final String email, final String password) {
|
||||||
return new StringRequest(Method.POST, AppConfig.REST_REGISTER, new Response.Listener<String>() {
|
return new StringRequest(Method.POST, AppConfig.REST_REGISTER, response -> {
|
||||||
|
Log.d(TAG, "Register Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Register Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
if (!error) {
|
||||||
|
new AlertDialog.Builder(LoginActivity.this)
|
||||||
try {
|
.setTitle(getString(R.string.alert_accregistration_title))
|
||||||
JSONObject jObj = new JSONObject(response);
|
.setMessage(getString(R.string.alert_accregistration_text))
|
||||||
boolean error = jObj.getBoolean("error");
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||||
if (!error) {
|
Intent intent = new Intent(
|
||||||
new AlertDialog.Builder(LoginActivity.this)
|
LoginActivity.this,
|
||||||
.setTitle(getString(R.string.alert_accregistration_title))
|
LoginActivity.class);
|
||||||
.setMessage(getString(R.string.alert_accregistration_text))
|
intent.putExtra(AppConfig.EXTRA_MESSAGE, AppConfig.INTENT_LOGIN);
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
startActivity(intent);
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
finish();
|
||||||
Intent intent = new Intent(
|
})
|
||||||
LoginActivity.this,
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
LoginActivity.class);
|
.show();
|
||||||
intent.putExtra(AppConfig.EXTRA_MESSAGE, AppConfig.INTENT_LOGIN);
|
} else {
|
||||||
startActivity(intent);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
finish();
|
Crashlytics.log(Log.ERROR, TAG, "Error occured: "+errorMsg);
|
||||||
}
|
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
||||||
})
|
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
||||||
.show();
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error occured: "+errorMsg);
|
|
||||||
Toast.makeText(getApplicationContext(), getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Registration Error: " + error.getMessage());
|
||||||
@Override
|
Toast.makeText(getApplicationContext(),
|
||||||
public void onErrorResponse(VolleyError error) {
|
getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Registration Error: " + error.getMessage());
|
hideDialog();
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
getResources().getString(R.string.txt_errormsg_register), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.deke.risk.riskahead;
|
package org.deke.risk.riskahead;
|
||||||
|
|
||||||
|
import android.app.ActionBar;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
import android.app.SearchableInfo;
|
import android.app.SearchableInfo;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -11,7 +12,9 @@ import android.graphics.Color;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
|
import android.location.LocationListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
@@ -20,10 +23,9 @@ import android.support.v4.content.CursorLoader;
|
|||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RatingBar;
|
import android.widget.RatingBar;
|
||||||
@@ -33,11 +35,6 @@ import android.widget.TextView;
|
|||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
|
|
||||||
import android.location.LocationListener;
|
|
||||||
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.google.android.gms.maps.CameraUpdate;
|
import com.google.android.gms.maps.CameraUpdate;
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||||
@@ -155,14 +152,14 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
|
||||||
Log.d(TAG, "Getting permission results...");
|
Log.d(TAG, "Getting permission results...");
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case MY_PERMISSIONS_REQUEST_LOCATION: {
|
case MY_PERMISSIONS_REQUEST_LOCATION: {
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
Log.d(TAG, "Permission was granted by user");
|
Log.d(TAG, "Permission was granted by user");
|
||||||
enableMyLocationButton();
|
enableMyLocationButton();
|
||||||
getLocation();
|
gotoMyLocation();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Permission was not granted by user");
|
Log.d(TAG, "Permission was not granted by user");
|
||||||
@@ -192,173 +189,161 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
Log.d(TAG, "Init Map");
|
Log.d(TAG, "Init Map");
|
||||||
mMap.getUiSettings().setZoomControlsEnabled(true);
|
mMap.getUiSettings().setZoomControlsEnabled(true);
|
||||||
mMap.setMinZoomPreference(MIN_ZOOM_LEVEL);
|
mMap.setMinZoomPreference(MIN_ZOOM_LEVEL);
|
||||||
mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() {
|
mMap.setOnMyLocationButtonClickListener(() -> {
|
||||||
@Override
|
gotoMyLocation();
|
||||||
public boolean onMyLocationButtonClick() {
|
return false;
|
||||||
getLocation();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Retrieve height of action bar and modify map padding
|
||||||
|
TypedValue tv = new TypedValue();
|
||||||
|
if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true))
|
||||||
|
{
|
||||||
|
int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
|
||||||
|
mMap.setPadding(0, actionBarHeight,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
enableMyLocationButton();
|
enableMyLocationButton();
|
||||||
|
|
||||||
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
|
mMap.setOnMapClickListener(point -> {
|
||||||
@Override
|
if (mMarker != null) {
|
||||||
public void onMapClick(LatLng point) {
|
mMarker.remove();
|
||||||
if (mMarker != null) {
|
}
|
||||||
mMarker.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
markedLocation = point;
|
markedLocation = point;
|
||||||
mMarker = mMap.addMarker(new MarkerOptions().position(point));
|
mMarker = mMap.addMarker(new MarkerOptions().position(point));
|
||||||
|
|
||||||
if (current_zoom_level > DEFAULT_ZOOM_LEVEL) {
|
if (current_zoom_level > DEFAULT_ZOOM_LEVEL) {
|
||||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, current_zoom_level));
|
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, current_zoom_level));
|
||||||
} else {
|
} else {
|
||||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, DEFAULT_ZOOM_LEVEL));
|
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(point, DEFAULT_ZOOM_LEVEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
addButton = findViewById(R.id.fab_reportwf_map);
|
addButton = findViewById(R.id.fab_reportwf_map);
|
||||||
addButton.setVisibility(View.VISIBLE);
|
addButton.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (getIntent().hasExtra(AppConfig.EXTRA_MAP_TYPE)) {
|
if (getIntent().hasExtra(AppConfig.EXTRA_MAP_TYPE)) {
|
||||||
if (getIntent().getStringExtra(AppConfig.EXTRA_MAP_TYPE).equals(AppConfig.INTENT_MAP_GETINCLOC)) {
|
if (getIntent().getStringExtra(AppConfig.EXTRA_MAP_TYPE).equals(AppConfig.INTENT_MAP_GETINCLOC)) {
|
||||||
addButton.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.md_green_400)));
|
addButton.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.md_green_400)));
|
||||||
showAdd = false;
|
showAdd = false;
|
||||||
Drawable identityIcon = new IconicsDrawable(getApplicationContext())
|
Drawable identityIcon = new IconicsDrawable(getApplicationContext())
|
||||||
.icon(GoogleMaterial.Icon.gmd_done)
|
.icon(GoogleMaterial.Icon.gmd_done)
|
||||||
.color(ContextCompat.getColor(getApplicationContext(), R.color.white))
|
.color(ContextCompat.getColor(getApplicationContext(), R.color.white))
|
||||||
.sizeDp(24);
|
.sizeDp(24);
|
||||||
|
|
||||||
addButton.setImageDrawable(identityIcon);
|
addButton.setImageDrawable(identityIcon);
|
||||||
|
|
||||||
addButton.setOnClickListener(new View.OnClickListener() {
|
addButton.setOnClickListener(v -> gotoReportActivity(markedLocation.latitude + ":" + markedLocation.longitude));
|
||||||
@Override
|
} else if (getIntent().getStringExtra(AppConfig.EXTRA_MAP_TYPE).equals(AppConfig.INTENT_MAP_GETNOTIFY)) {
|
||||||
public void onClick(View v) {
|
addButton.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.md_green_400)));
|
||||||
gotoReportActivity(markedLocation.latitude + ":" + markedLocation.longitude);
|
showAdd = false;
|
||||||
}
|
Drawable identityIcon = new IconicsDrawable(getApplicationContext())
|
||||||
});
|
.icon(GoogleMaterial.Icon.gmd_done)
|
||||||
} else if (getIntent().getStringExtra(AppConfig.EXTRA_MAP_TYPE).equals(AppConfig.INTENT_MAP_GETNOTIFY)) {
|
.color(ContextCompat.getColor(getApplicationContext(), R.color.white))
|
||||||
addButton.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.md_green_400)));
|
.sizeDp(24);
|
||||||
showAdd = false;
|
|
||||||
Drawable identityIcon = new IconicsDrawable(getApplicationContext())
|
|
||||||
.icon(GoogleMaterial.Icon.gmd_done)
|
|
||||||
.color(ContextCompat.getColor(getApplicationContext(), R.color.white))
|
|
||||||
.sizeDp(24);
|
|
||||||
|
|
||||||
addButton.setImageDrawable(identityIcon);
|
addButton.setImageDrawable(identityIcon);
|
||||||
|
|
||||||
addButton.setOnClickListener(new View.OnClickListener() {
|
addButton.setOnClickListener(v -> {
|
||||||
@Override
|
session.setManualLocation(Double.doubleToRawLongBits(markedLocation.latitude), Double.doubleToRawLongBits(markedLocation.longitude));
|
||||||
public void onClick(View v) {
|
Log.d(TAG, "MARKED LOCATION: " + markedLocation.latitude + " " + markedLocation.longitude);
|
||||||
session.setManualLocation(Double.doubleToRawLongBits(markedLocation.latitude), Double.doubleToRawLongBits(markedLocation.longitude));
|
gotoSettingsActivity();
|
||||||
Log.d(TAG, "MARKED LOCATION: " + markedLocation.latitude + " " + markedLocation.longitude);
|
|
||||||
gotoSettingsActivity();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Log.d(TAG, "MARKED LOCATION: " + markedLocation.latitude + " " + markedLocation.longitude);
|
|
||||||
showAdd = false;
|
|
||||||
gotoReportActivity(markedLocation.latitude + ":" + markedLocation.longitude);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
addButton.setOnClickListener(v -> {
|
||||||
|
Log.d(TAG, "MARKED LOCATION: " + markedLocation.latitude + " " + markedLocation.longitude);
|
||||||
|
showAdd = false;
|
||||||
|
gotoReportActivity(markedLocation.latitude + ":" + markedLocation.longitude);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoogleMap.OnCameraIdleListener getCameraChangeListener() {
|
public GoogleMap.OnCameraIdleListener getCameraChangeListener() {
|
||||||
return new GoogleMap.OnCameraIdleListener() {
|
return () -> {
|
||||||
@Override
|
mClusterManager.onCameraIdle();
|
||||||
public void onCameraIdle() {
|
CameraPosition position = mMap.getCameraPosition();
|
||||||
mClusterManager.onCameraIdle();
|
current_zoom_level = position.zoom;
|
||||||
CameraPosition position = mMap.getCameraPosition();
|
|
||||||
current_zoom_level = position.zoom;
|
|
||||||
|
|
||||||
if (position.zoom > 13) {
|
if (position.zoom > 13) {
|
||||||
PRELOAD_PERCENTAGE = 0.7;
|
PRELOAD_PERCENTAGE = 0.7;
|
||||||
} else {
|
} else {
|
||||||
PRELOAD_PERCENTAGE = 0.3;
|
PRELOAD_PERCENTAGE = 0.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
|
||||||
|
|
||||||
|
Log.d("OnCameraChangeListener", "Position: " + bounds.getCenter() + " Zoom: " + position.zoom + " Bounds: NE:" + bounds.northeast + " SW: " + bounds.southwest);
|
||||||
|
Log.d("OnCameraChangeListener", "Saved Position - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
|
||||||
|
|
||||||
|
boolean isOutOfBounds = false;
|
||||||
|
|
||||||
|
double distanceLat = Math.abs(bounds.northeast.latitude - bounds.southwest.latitude);
|
||||||
|
double distanceLon = Math.abs(bounds.northeast.longitude - bounds.southwest.longitude);
|
||||||
|
|
||||||
|
double southwestLat, southwestLng;
|
||||||
|
double northeastLat, northeastLng;
|
||||||
|
|
||||||
|
if (bounds.southwest.latitude < bounds.northeast.latitude) {
|
||||||
|
southwestLat = bounds.southwest.latitude - distanceLat * PRELOAD_PERCENTAGE;
|
||||||
|
northeastLat = bounds.northeast.latitude + distanceLat * PRELOAD_PERCENTAGE;
|
||||||
|
|
||||||
|
if ((curSouthwestBounds != null) && ((bounds.southwest.latitude < curSouthwestBounds.latitude) || (bounds.northeast.latitude > curNortheastBounds.latitude))) {
|
||||||
|
isOutOfBounds = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
southwestLat = bounds.southwest.latitude + distanceLat * PRELOAD_PERCENTAGE;
|
||||||
|
northeastLat = bounds.northeast.latitude - distanceLat * PRELOAD_PERCENTAGE;
|
||||||
|
|
||||||
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
|
if ((curSouthwestBounds != null) && ((bounds.southwest.latitude > curSouthwestBounds.latitude) || (bounds.northeast.latitude < curNortheastBounds.latitude))) {
|
||||||
|
isOutOfBounds = true;
|
||||||
Log.d("OnCameraChangeListener", "Position: " + bounds.getCenter() + " Zoom: " + position.zoom + " Bounds: NE:" + bounds.northeast + " SW: " + bounds.southwest);
|
|
||||||
Log.d("OnCameraChangeListener", "Saved Position - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
|
|
||||||
|
|
||||||
boolean isOutOfBounds = false;
|
|
||||||
|
|
||||||
double distanceLat = Math.abs(bounds.northeast.latitude - bounds.southwest.latitude);
|
|
||||||
double distanceLon = Math.abs(bounds.northeast.longitude - bounds.southwest.longitude);
|
|
||||||
|
|
||||||
double southwestLat, southwestLng;
|
|
||||||
double northeastLat, northeastLng;
|
|
||||||
|
|
||||||
if (bounds.southwest.latitude < bounds.northeast.latitude) {
|
|
||||||
southwestLat = bounds.southwest.latitude - distanceLat * PRELOAD_PERCENTAGE;
|
|
||||||
northeastLat = bounds.northeast.latitude + distanceLat * PRELOAD_PERCENTAGE;
|
|
||||||
|
|
||||||
if ((curSouthwestBounds != null) && ((bounds.southwest.latitude < curSouthwestBounds.latitude) || (bounds.northeast.latitude > curNortheastBounds.latitude))) {
|
|
||||||
isOutOfBounds = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
southwestLat = bounds.southwest.latitude + distanceLat * PRELOAD_PERCENTAGE;
|
|
||||||
northeastLat = bounds.northeast.latitude - distanceLat * PRELOAD_PERCENTAGE;
|
|
||||||
|
|
||||||
if ((curSouthwestBounds != null) && ((bounds.southwest.latitude > curSouthwestBounds.latitude) || (bounds.northeast.latitude < curNortheastBounds.latitude))) {
|
|
||||||
isOutOfBounds = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bounds.southwest.longitude < bounds.northeast.longitude) {
|
if (bounds.southwest.longitude < bounds.northeast.longitude) {
|
||||||
southwestLng = bounds.southwest.longitude - distanceLon * PRELOAD_PERCENTAGE;
|
southwestLng = bounds.southwest.longitude - distanceLon * PRELOAD_PERCENTAGE;
|
||||||
northeastLng = bounds.northeast.longitude + distanceLon * PRELOAD_PERCENTAGE;
|
northeastLng = bounds.northeast.longitude + distanceLon * PRELOAD_PERCENTAGE;
|
||||||
|
|
||||||
if ((curSouthwestBounds != null) && ((bounds.southwest.longitude < curSouthwestBounds.longitude) || (bounds.northeast.longitude > curNortheastBounds.longitude))) {
|
if ((curSouthwestBounds != null) && ((bounds.southwest.longitude < curSouthwestBounds.longitude) || (bounds.northeast.longitude > curNortheastBounds.longitude))) {
|
||||||
isOutOfBounds = true;
|
isOutOfBounds = true;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
southwestLng = bounds.southwest.longitude + distanceLon * PRELOAD_PERCENTAGE;
|
|
||||||
northeastLng = bounds.northeast.longitude - distanceLon * PRELOAD_PERCENTAGE;
|
|
||||||
|
|
||||||
if ((curSouthwestBounds != null) && ((bounds.southwest.longitude > curSouthwestBounds.longitude) || (bounds.northeast.longitude < curNortheastBounds.longitude))) {
|
|
||||||
isOutOfBounds = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
southwestLng = bounds.southwest.longitude + distanceLon * PRELOAD_PERCENTAGE;
|
||||||
|
northeastLng = bounds.northeast.longitude - distanceLon * PRELOAD_PERCENTAGE;
|
||||||
|
|
||||||
if ((curSouthwestBounds == null) || isOutOfBounds) {
|
if ((curSouthwestBounds != null) && ((bounds.southwest.longitude > curSouthwestBounds.longitude) || (bounds.northeast.longitude < curNortheastBounds.longitude))) {
|
||||||
curNortheastBounds = new LatLng(northeastLat, northeastLng);
|
isOutOfBounds = true;
|
||||||
curSouthwestBounds = new LatLng(southwestLat, southwestLng);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log.d("OnCameraChangeListener", "isOutOfBounds is true => New Calculated - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
|
if ((curSouthwestBounds == null) || isOutOfBounds) {
|
||||||
|
curNortheastBounds = new LatLng(northeastLat, northeastLng);
|
||||||
|
curSouthwestBounds = new LatLng(southwestLat, southwestLng);
|
||||||
|
|
||||||
if (position.zoom >= THRESHOLD_ZOOM_LEVEL) {
|
Log.d("OnCameraChangeListener", "isOutOfBounds is true => New Calculated - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
|
||||||
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
|
|
||||||
refreshIncidentMarkers(curNortheastBounds, curSouthwestBounds);
|
|
||||||
markersShown = true;
|
|
||||||
} else if (position.zoom < THRESHOLD_ZOOM_LEVEL) {
|
|
||||||
mClusterManager.clearItems();
|
|
||||||
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
|
|
||||||
markersShown = false;
|
|
||||||
}
|
|
||||||
} else if ((position.zoom >= THRESHOLD_ZOOM_LEVEL) && !markersShown) {
|
|
||||||
curNortheastBounds = new LatLng(northeastLat, northeastLng);
|
|
||||||
curSouthwestBounds = new LatLng(southwestLat, southwestLng);
|
|
||||||
|
|
||||||
Log.d("OnCameraChangeListener", "zoom threshold passed => New Calculated - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
|
|
||||||
|
|
||||||
|
if (position.zoom >= THRESHOLD_ZOOM_LEVEL) {
|
||||||
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
|
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
|
||||||
refreshIncidentMarkers(curNortheastBounds, curSouthwestBounds);
|
refreshIncidentMarkers(curNortheastBounds, curSouthwestBounds);
|
||||||
markersShown = true;
|
markersShown = true;
|
||||||
} else if ((position.zoom < THRESHOLD_ZOOM_LEVEL) && !markersShown) {
|
} else if (position.zoom < THRESHOLD_ZOOM_LEVEL) {
|
||||||
mClusterManager.clearItems();
|
mClusterManager.clearItems();
|
||||||
|
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
|
||||||
markersShown = false;
|
markersShown = false;
|
||||||
}
|
}
|
||||||
|
} else if ((position.zoom >= THRESHOLD_ZOOM_LEVEL) && !markersShown) {
|
||||||
|
curNortheastBounds = new LatLng(northeastLat, northeastLng);
|
||||||
|
curSouthwestBounds = new LatLng(southwestLat, southwestLng);
|
||||||
|
|
||||||
|
Log.d("OnCameraChangeListener", "zoom threshold passed => New Calculated - Bounds: NE:" + curNortheastBounds + " SW: " + curSouthwestBounds);
|
||||||
|
|
||||||
|
refreshIncidentHeatMap(curNortheastBounds, curSouthwestBounds);
|
||||||
|
refreshIncidentMarkers(curNortheastBounds, curSouthwestBounds);
|
||||||
|
markersShown = true;
|
||||||
|
} else if ((position.zoom < THRESHOLD_ZOOM_LEVEL) && !markersShown) {
|
||||||
|
mClusterManager.clearItems();
|
||||||
|
markersShown = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -421,39 +406,32 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetAllIncidentsForHeatMapFromBound(final LatLng northeast, final LatLng southwest) {
|
private StringRequest getStringRequestGetAllIncidentsForHeatMapFromBound(final LatLng northeast, final LatLng southwest) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMBOUND_FORHEATMAP, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMBOUND_FORHEATMAP, response -> {
|
||||||
|
Log.d(TAG, "Map HeatMap positions response: " + response);
|
||||||
|
hideProgress();
|
||||||
|
try {
|
||||||
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
@Override
|
if (!error) {
|
||||||
public void onResponse(String response) {
|
JSONArray incidents = jObj.getJSONArray("msg");
|
||||||
Log.d(TAG, "Map HeatMap positions response: " + response);
|
Log.d(TAG, "HeatMap positions response length: " + incidents.length());
|
||||||
hideProgress();
|
addIncidentMarkersOnHeatMap(incidents);
|
||||||
try {
|
} else {
|
||||||
JSONObject jObj = new JSONObject(response);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
|
||||||
|
|
||||||
if (!error) {
|
int loglevel = errorMsg.contains("Could not retrieve incidents from bound") ? Log.INFO : Log.ERROR;
|
||||||
JSONArray incidents = jObj.getJSONArray("msg");
|
Crashlytics.log(loglevel, TAG, "Error getting map heat map positions (server returned error): " + errorMsg);
|
||||||
Log.d(TAG, "HeatMap positions response length: " + incidents.length());
|
|
||||||
addIncidentMarkersOnHeatMap(incidents);
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
|
|
||||||
int loglevel = errorMsg.contains("Could not retrieve incidents from bound") ? Log.INFO : Log.ERROR;
|
|
||||||
Crashlytics.log(loglevel, TAG, "Error getting map heat map positions (server returned error): " + errorMsg);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}, error -> {
|
||||||
}, new Response.ErrorListener() {
|
hideProgress();
|
||||||
@Override
|
Crashlytics.log(Log.ERROR, TAG, "Error getting map positions: " + error.getMessage());
|
||||||
public void onErrorResponse(VolleyError error) {
|
handleVolleyErrorResponse();
|
||||||
hideProgress();
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting map positions: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
@@ -471,37 +449,30 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetAllIncidentsFromBound(final LatLng northeast, final LatLng southwest) {
|
private StringRequest getStringRequestGetAllIncidentsFromBound(final LatLng northeast, final LatLng southwest) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMBOUND, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMBOUND, response -> {
|
||||||
|
Log.d(TAG, "Map positions response: " + response);
|
||||||
|
hideProgress();
|
||||||
|
try {
|
||||||
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
@Override
|
if (!error) {
|
||||||
public void onResponse(String response) {
|
JSONArray incidents = jObj.getJSONArray("msg");
|
||||||
Log.d(TAG, "Map positions response: " + response);
|
Log.d(TAG, "Map positions response length: " + incidents.length());
|
||||||
hideProgress();
|
addIncidentMarkersOnMap(incidents);
|
||||||
try {
|
} else {
|
||||||
JSONObject jObj = new JSONObject(response);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
Crashlytics.log(Log.INFO, TAG, "Error getting map positions (server returned error): " + errorMsg);
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
JSONArray incidents = jObj.getJSONArray("msg");
|
|
||||||
Log.d(TAG, "Map positions response length: " + incidents.length());
|
|
||||||
addIncidentMarkersOnMap(incidents);
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.INFO, TAG, "Error getting map positions (server returned error): " + errorMsg);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}, error -> {
|
||||||
}, new Response.ErrorListener() {
|
hideProgress();
|
||||||
@Override
|
Crashlytics.log(Log.ERROR, TAG, "Error getting map positions: " + error.getMessage());
|
||||||
public void onErrorResponse(VolleyError error) {
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
hideProgress();
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting map positions: " + error.getMessage());
|
|
||||||
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
@@ -532,12 +503,9 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
|
|
||||||
mClusterManager.setOnClusterClickListener(this);
|
mClusterManager.setOnClusterClickListener(this);
|
||||||
mClusterManager.setOnClusterItemClickListener(this);
|
mClusterManager.setOnClusterItemClickListener(this);
|
||||||
mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<IncidentReport>() {
|
mClusterManager.setOnClusterItemClickListener(item -> {
|
||||||
@Override
|
clickedClusterItem = item;
|
||||||
public boolean onClusterItemClick(IncidentReport item) {
|
return false;
|
||||||
clickedClusterItem = item;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(
|
mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(
|
||||||
@@ -553,48 +521,41 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetIncidentScoreForInfoWindow(final View infoView, final String incidentID) {
|
private StringRequest getStringRequestGetIncidentScoreForInfoWindow(final View infoView, final String incidentID) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENT, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENT, response -> {
|
||||||
|
Log.d(TAG, "Map positions response: " + response);
|
||||||
|
hideProgress();
|
||||||
|
try {
|
||||||
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
@Override
|
if (!error) {
|
||||||
public void onResponse(String response) {
|
JSONObject incident = jObj.getJSONObject("msg");
|
||||||
Log.d(TAG, "Map positions response: " + response);
|
clickedClusterItem = new IncidentReport(incident);
|
||||||
hideProgress();
|
|
||||||
try {
|
|
||||||
JSONObject jObj = new JSONObject(response);
|
|
||||||
boolean error = jObj.getBoolean("error");
|
|
||||||
|
|
||||||
if (!error) {
|
TextView tvUsername = infoView.findViewById(R.id.txt_infowindow_fromuser);
|
||||||
JSONObject incident = jObj.getJSONObject("msg");
|
RatingBar rbScore = infoView.findViewById(R.id.rb_infowindow_rating);
|
||||||
clickedClusterItem = new IncidentReport(incident);
|
|
||||||
|
|
||||||
TextView tvUsername = infoView.findViewById(R.id.txt_infowindow_fromuser);
|
tvUsername.setText(String.format("%s %s", getString(R.string.lbl_mapsinfowindow_author), clickedClusterItem.getFromUsername()));
|
||||||
RatingBar rbScore = infoView.findViewById(R.id.rb_infowindow_rating);
|
rbScore.setRating(clickedClusterItem.getScoreStars());
|
||||||
|
|
||||||
tvUsername.setText(String.format("%s %s", getString(R.string.lbl_mapsinfowindow_author), clickedClusterItem.getFromUsername()));
|
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) {
|
||||||
rbScore.setRating(clickedClusterItem.getScoreStars());
|
markerShowingInfoWindow.showInfoWindow();
|
||||||
|
markerShowingInfoWindow = null;
|
||||||
if (markerShowingInfoWindow != null && markerShowingInfoWindow.isInfoWindowShown()) {
|
|
||||||
markerShowingInfoWindow.showInfoWindow();
|
|
||||||
markerShowingInfoWindow = null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Log.i(TAG, "Error getting incident details (server returned error): " + errorMsg);
|
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_getinfowindow));
|
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} else {
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Crashlytics.logException(e);
|
Log.i(TAG, "Error getting incident details (server returned error): " + errorMsg);
|
||||||
|
showMessage(getResources().getString(R.string.txt_errormsg_getinfowindow));
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}, error -> {
|
||||||
}, new Response.ErrorListener() {
|
hideProgress();
|
||||||
@Override
|
Crashlytics.log(Log.ERROR, TAG, "Error getting incident details: " + error.getMessage());
|
||||||
public void onErrorResponse(VolleyError error) {
|
handleVolleyErrorResponse();
|
||||||
hideProgress();
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting incident details: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
@@ -674,7 +635,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
if ((myPosition != null) && (myPosition.latitude != 0.0) && (myPosition.longitude != 0.0)) {
|
if ((myPosition != null) && (myPosition.latitude != 0.0) && (myPosition.longitude != 0.0)) {
|
||||||
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(myPosition.latitude, myPosition.longitude), DEFAULT_ZOOM_LEVEL));
|
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(myPosition.latitude, myPosition.longitude), DEFAULT_ZOOM_LEVEL));
|
||||||
} else {
|
} else {
|
||||||
getLocation();
|
gotoMyLocation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -714,7 +675,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
getSupportLoaderManager().restartLoader(1, data, this);
|
getSupportLoaderManager().restartLoader(1, data, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showLocations(Cursor c) {
|
private void showLocation(Cursor c) {
|
||||||
MarkerOptions markerOptions;
|
MarkerOptions markerOptions;
|
||||||
LatLng position = null;
|
LatLng position = null;
|
||||||
|
|
||||||
@@ -736,16 +697,17 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<Cursor> arg0) {
|
public void onLoaderReset(@NonNull Loader<Cursor> arg0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle query) {
|
public Loader<Cursor> onCreateLoader(int arg0, Bundle query) {
|
||||||
CursorLoader cLoader;
|
CursorLoader cLoader;
|
||||||
|
|
||||||
if (arg0 == 0)
|
if (arg0 == 0)
|
||||||
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{query.getString("query")}, null);
|
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{query.getString("query")}, null);
|
||||||
else //if (arg0 == 1)
|
else
|
||||||
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{query.getString("query")}, null);
|
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{query.getString("query")}, null);
|
||||||
|
|
||||||
return cLoader;
|
return cLoader;
|
||||||
@@ -785,7 +747,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public void gotoMyLocation() {
|
||||||
//check for permission
|
//check for permission
|
||||||
Log.d(TAG, "Permission for GPS not granted yet - ask for permission now");
|
Log.d(TAG, "Permission for GPS not granted yet - ask for permission now");
|
||||||
if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
@@ -841,25 +803,22 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
Crashlytics.logException(e);
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return location;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableMyLocationButton() {
|
private void enableMyLocationButton() {
|
||||||
try{
|
try{
|
||||||
mMap.setMyLocationEnabled(true);
|
mMap.setMyLocationEnabled(true);
|
||||||
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.frag_maps_map);
|
|
||||||
View locationButton = ((View) mapFragment.getView().findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
|
|
||||||
RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams();
|
|
||||||
rlp.setMargins(0, 250, 30, 30);
|
|
||||||
}catch(SecurityException se){
|
}catch(SecurityException se){
|
||||||
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_REQUEST_LOCATION);
|
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION}, MY_PERMISSIONS_REQUEST_LOCATION);
|
||||||
|
}catch(AssertionError ae){
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Could not find mapFragment view");
|
||||||
|
Crashlytics.logException(ae);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<Cursor> arg0, Cursor c) {
|
public void onLoadFinished(@NonNull Loader<Cursor> arg0, Cursor c) {
|
||||||
showLocations(c);
|
showLocation(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import android.net.Uri;
|
|||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Address;
|
import android.location.Address;
|
||||||
@@ -24,8 +23,6 @@ import android.widget.TextView;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
|
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
|
||||||
@@ -124,36 +121,27 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
private void initButtonsAndElements() {
|
private void initButtonsAndElements() {
|
||||||
btnContinue = findViewById(R.id.btn_reportwf_next);
|
btnContinue = findViewById(R.id.btn_reportwf_next);
|
||||||
btnContinue.setEnabled(false);
|
btnContinue.setEnabled(false);
|
||||||
btnContinue.setOnClickListener(new View.OnClickListener() {
|
btnContinue.setOnClickListener(v -> {
|
||||||
@Override
|
incident = fragList.get(currentState).getCurrentInput();
|
||||||
public void onClick(View v) {
|
initFragment(currentState + 1);
|
||||||
incident = fragList.get(currentState).getCurrentInput();
|
|
||||||
initFragment(currentState + 1);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
btnReportNow = findViewById(R.id.btn_reportwf_reportnow);
|
btnReportNow = findViewById(R.id.btn_reportwf_reportnow);
|
||||||
btnReportNow.setEnabled(false);
|
btnReportNow.setEnabled(false);
|
||||||
btnReportNow.setOnClickListener(new View.OnClickListener() {
|
btnReportNow.setOnClickListener(v -> {
|
||||||
@Override
|
incident = fragList.get(currentState).getCurrentInput();
|
||||||
public void onClick(View v) {
|
sendReport();
|
||||||
incident = fragList.get(currentState).getCurrentInput();
|
|
||||||
sendReport();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
siteIndicator = findViewById(R.id.lbl_reportwf_site);
|
siteIndicator = findViewById(R.id.lbl_reportwf_site);
|
||||||
|
|
||||||
btnMap = findViewById(R.id.fab_reportwf_map);
|
btnMap = findViewById(R.id.fab_reportwf_map);
|
||||||
btnMap.setOnClickListener(new View.OnClickListener() {
|
btnMap.setOnClickListener(v -> {
|
||||||
@Override
|
incident = fragList.get(currentState).getCurrentInput();
|
||||||
public void onClick(View v) {
|
if (incident != null && incident.getPosition() != null) {
|
||||||
incident = fragList.get(currentState).getCurrentInput();
|
getIncidentLocationFromMapActivity(incident.getPosition().latitude + ":" + incident.getPosition().longitude);
|
||||||
if (incident != null && incident.getPosition() != null) {
|
} else {
|
||||||
getIncidentLocationFromMapActivity(incident.getPosition().latitude + ":" + incident.getPosition().longitude);
|
getIncidentLocationFromMapActivity();
|
||||||
} else {
|
|
||||||
getIncidentLocationFromMapActivity();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -196,7 +184,9 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
private void modifyPos(String pos){
|
private void modifyPos(String pos){
|
||||||
String[] position = pos.split(":");
|
String[] position = pos.split(":");
|
||||||
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
|
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
|
||||||
LatLng latlngpos = new LatLng(Double.parseDouble(position[0]), Double.parseDouble(position[1]));
|
LatLng latlngpos = new LatLng(
|
||||||
|
Double.parseDouble(position[0]),
|
||||||
|
Double.parseDouble(position[1]));
|
||||||
incident.setPosition(latlngpos);
|
incident.setPosition(latlngpos);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -204,16 +194,12 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
|
|
||||||
if (addressList != null && addressList.size() > 0) {
|
if (addressList != null && addressList.size() > 0) {
|
||||||
Address address = addressList.get(0);
|
Address address = addressList.get(0);
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
|
if(address.getAddressLine(0) != null){
|
||||||
if(address.getAddressLine(i) != null) sb.append(address.getAddressLine(i)).append("\n");
|
incident.setIncidentPositionDescription(
|
||||||
|
address.getAddressLine(0).replace(", ", "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(address.getCountryName() != null) sb.append(address.getCountryName());
|
|
||||||
incident.setIncidentPositionDescription(sb.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
Crashlytics.logException(e);
|
Crashlytics.logException(e);
|
||||||
@@ -275,20 +261,16 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
new AlertDialog.Builder(ReportWFActivity.this)
|
new AlertDialog.Builder(ReportWFActivity.this)
|
||||||
.setTitle(getResources().getString(R.string.txt_reportwf_newincidenttitle))
|
.setTitle(getResources().getString(R.string.txt_reportwf_newincidenttitle))
|
||||||
.setMessage(getResources().getString(R.string.txt_reportwf_newincidenttext))
|
.setMessage(getResources().getString(R.string.txt_reportwf_newincidenttext))
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
resetStateAndIncident();
|
||||||
resetStateAndIncident();
|
initFragment(0);
|
||||||
initFragment(0);
|
|
||||||
|
|
||||||
if(currentState == 0){
|
if(currentState == 0){
|
||||||
gotoReportActivity();
|
gotoReportActivity();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
// do nothing
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
@@ -316,38 +298,31 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
|
|
||||||
private StringRequest getStringRequestAddIncidentWithPosition(final IncidentReport incident) {
|
private StringRequest getStringRequestAddIncidentWithPosition(final IncidentReport incident) {
|
||||||
showDialog();
|
showDialog();
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_ADD_INCIDENT_WITHPOSITION, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_ADD_INCIDENT_WITHPOSITION, response -> {
|
||||||
|
Log.d(TAG, "Report response: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Report response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
showMessage(getString(R.string.txt_success_addreport));
|
||||||
boolean error = jObj.getBoolean("error");
|
showShareDialog(incident);
|
||||||
|
} else {
|
||||||
if (!error) {
|
String errorMsg = jObj.getString("error_msg");
|
||||||
showMessage(getString(R.string.txt_success_addreport));
|
Crashlytics.log(Log.ERROR, TAG, "Error adding incident (Server returned error): " + errorMsg);
|
||||||
showShareDialog(incident);
|
showMessage(getResources().getString(R.string.txt_errormsg_createincident));
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error adding incident (Server returned error): " + errorMsg);
|
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_createincident));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}, error -> {
|
||||||
}, new Response.ErrorListener() {
|
Crashlytics.log(Log.ERROR, TAG, "Error adding incident: " + error.getMessage());
|
||||||
@Override
|
handleVolleyErrorResponse();
|
||||||
public void onErrorResponse(VolleyError error) {
|
hideDialog();
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error adding incident: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -410,16 +385,8 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
new AlertDialog.Builder(ReportWFActivity.this)
|
new AlertDialog.Builder(ReportWFActivity.this)
|
||||||
.setTitle(R.string.txt_share_title)
|
.setTitle(R.string.txt_share_title)
|
||||||
.setMessage(R.string.txt_share_message)
|
.setMessage(R.string.txt_share_message)
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> startShareIncidentIntent(incident))
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setNegativeButton(android.R.string.no, (dialog, which) -> finishReportAndGotoMap(incident))
|
||||||
startShareIncidentIntent(incident);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
finishReportAndGotoMap(incident);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
@@ -432,11 +399,9 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
alertDialog.setTitle("Request Permission");
|
alertDialog.setTitle("Request Permission");
|
||||||
alertDialog.setMessage("If you want to use the sharing feature in the future we need storage permission to generate the message which should be shared.");
|
alertDialog.setMessage("If you want to use the sharing feature in the future we need storage permission to generate the message which should be shared.");
|
||||||
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
|
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
dialog.dismiss();
|
||||||
dialog.dismiss();
|
requestPermission();
|
||||||
requestPermission();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
|
|
||||||
@@ -447,10 +412,22 @@ public class ReportWFActivity extends BaseActivity implements ReportWF_1_Fragmen
|
|||||||
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
|
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
|
||||||
Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),
|
Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),
|
||||||
R.drawable.ra_qrcode);
|
R.drawable.ra_qrcode);
|
||||||
|
|
||||||
|
String[] posDesc = incident.getIncidentPositionDescription().split("\\n");
|
||||||
|
String locationText = "";
|
||||||
|
|
||||||
|
if(posDesc.length > 1){
|
||||||
|
locationText = posDesc[0] + " - " +posDesc[1];
|
||||||
|
}else if(posDesc.length == 1){
|
||||||
|
locationText = posDesc[0];
|
||||||
|
}else{
|
||||||
|
Log.e(TAG, "Could not find location desciption");
|
||||||
|
}
|
||||||
|
|
||||||
String text = getString(R.string.txt_share_hint)
|
String text = getString(R.string.txt_share_hint)
|
||||||
+getString(R.string.txt_share_hint2)+": "+ incident.getIncidentCategoryName(getApplicationContext())
|
+getString(R.string.txt_share_hint2)+": "+ incident.getIncidentCategoryName(getApplicationContext())
|
||||||
+" - "+incident.getIncidentSubCategoryName(getApplicationContext())+"\n"
|
+" - "+incident.getIncidentSubCategoryName(getApplicationContext())+"\n"
|
||||||
+getString(R.string.txt_share_hint3)+": "+ incident.getIncidentPositionDescription().split("\\n")[0] + " - " + incident.getIncidentPositionDescription().split("\\n")[1] + "\n"
|
+getString(R.string.txt_share_hint3)+": "+ locationText + "\n"
|
||||||
+getString(R.string.txt_share_page);
|
+getString(R.string.txt_share_page);
|
||||||
|
|
||||||
sharingIntent.putExtra(Intent.EXTRA_TEXT, text);
|
sharingIntent.putExtra(Intent.EXTRA_TEXT, text);
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ import android.widget.LinearLayout;
|
|||||||
|
|
||||||
import com.android.vending.billing.IInAppBillingService;
|
import com.android.vending.billing.IInAppBillingService;
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
@@ -317,38 +315,30 @@ public class SubscriptionsActivity extends BaseActivity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringAddSubscription(final String productId, final String type, final String price, final String currency) {
|
private StringRequest getStringAddSubscription(final String productId, final String type, final String price, final String currency) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_ADD_SUBSCRIPTIONS, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_ADD_SUBSCRIPTIONS, response -> {
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
Crashlytics.log(Log.ERROR, TAG, "Error adding subscription (Server returned error): " + errorMsg);
|
||||||
|
showMessage(getResources().getString(R.string.txt_errormsg_subs));
|
||||||
if (error) {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
gotoSubscriptionsActivity();
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error adding subscription (Server returned error): " + errorMsg);
|
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_subs));
|
|
||||||
} else {
|
|
||||||
gotoSubscriptionsActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hideDialog();
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
hideDialog();
|
||||||
public void onErrorResponse(VolleyError error) {
|
}, error -> {
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error adding subscription: " + error.getMessage());
|
Crashlytics.log(Log.ERROR, TAG, "Error adding subscription: " + error.getMessage());
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_subs));
|
showMessage(getResources().getString(R.string.txt_errormsg_subs));
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -373,44 +363,36 @@ public class SubscriptionsActivity extends BaseActivity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringGetSubscriptions(final String userId) {
|
private StringRequest getStringGetSubscriptions(final String userId) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_SUBSCRIPTIONS, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_SUBSCRIPTIONS, response -> {
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
dbItems = new HashMap<>();
|
||||||
|
|
||||||
try {
|
if (error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
Log.d(TAG, "Error getting subscription (Server returned error): " + errorMsg);
|
||||||
dbItems = new HashMap<>();
|
dbItems = null;
|
||||||
|
|
||||||
if (error) {
|
}else{
|
||||||
String errorMsg = jObj.getString("error_msg");
|
JSONArray subs = jObj.getJSONArray("msg");
|
||||||
Log.d(TAG, "Error getting subscription (Server returned error): " + errorMsg);
|
Log.d(TAG, "SUB FROM DB RECEIVED");
|
||||||
dbItems = null;
|
|
||||||
|
|
||||||
}else{
|
for(int i = 0;i < subs.length();i++){
|
||||||
JSONArray subs = jObj.getJSONArray("msg");
|
dbItems.put(subs.getJSONObject(i).getString("productId"),subs.getJSONObject(i).getString("id"));
|
||||||
Log.d(TAG, "SUB FROM DB RECEIVED");
|
|
||||||
|
|
||||||
for(int i = 0;i < subs.length();i++){
|
|
||||||
dbItems.put(subs.getJSONObject(i).getString("productId"),subs.getJSONObject(i).getString("id"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncWithDatabase(ownedSkus);
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
syncWithDatabase(ownedSkus);
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting subscription: " + error.getMessage());
|
} catch (JSONException e) {
|
||||||
handleVolleyErrorResponse();
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting subscription: " + error.getMessage());
|
||||||
|
handleVolleyErrorResponse();
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -434,34 +416,24 @@ public class SubscriptionsActivity extends BaseActivity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringDeactivateSubscriptions(final String subscriptionId) {
|
private StringRequest getStringDeactivateSubscriptions(final String subscriptionId) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_DEACTIVATE_SUBSCRIPTIONS, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_DEACTIVATE_SUBSCRIPTIONS, response -> {
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
String errorMsg = jObj.getString("error_msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
Crashlytics.log(Log.ERROR, TAG, "Error deactivating subscription (Server returned error): " + errorMsg);
|
||||||
|
}else{
|
||||||
if (error) {
|
Log.d(TAG,"Sub with uid: "+subscriptionId+" deactivated in DB");
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error deactivating subscription (Server returned error): " + errorMsg);
|
|
||||||
}else{
|
|
||||||
Log.d(TAG,"Sub with uid: "+subscriptionId+" deactivated in DB");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
} catch (JSONException e) {
|
||||||
public void onErrorResponse(VolleyError error) {
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error deactivating subscription: " + error.getMessage());
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}) {
|
}, error -> Crashlytics.log(Log.ERROR, TAG, "Error deactivating subscription: " + error.getMessage())) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.deke.risk.riskahead;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.location.Address;
|
import android.location.Address;
|
||||||
@@ -15,8 +14,6 @@ import android.view.View;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.beardedhen.androidbootstrap.AwesomeTextView;
|
import com.beardedhen.androidbootstrap.AwesomeTextView;
|
||||||
import com.beardedhen.androidbootstrap.BootstrapLabel;
|
import com.beardedhen.androidbootstrap.BootstrapLabel;
|
||||||
@@ -101,41 +98,19 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
final Integer id = intent.getIntExtra(BaseActivity.EXTRA_MESSAGE, 0);
|
final Integer id = intent.getIntExtra(BaseActivity.EXTRA_MESSAGE, 0);
|
||||||
getIncident(id);
|
getIncident(id);
|
||||||
|
|
||||||
btnUpvote.setOnClickListener(new View.OnClickListener() {
|
btnUpvote.setOnClickListener(v -> makeUpvote(id));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
makeUpvote(id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
findViewById(R.id.layoutFooter).setVisibility(View.GONE);
|
findViewById(R.id.layoutFooter).setVisibility(View.GONE);
|
||||||
btnDownvote.setOnClickListener(new View.OnClickListener() {
|
btnDownvote.setOnClickListener(v -> makeDownvote(id));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
makeDownvote(id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.btn_viewreport_delete).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.btn_viewreport_delete).setOnClickListener(v -> new AlertDialog.Builder(ViewReportActivity.this)
|
||||||
@Override
|
.setTitle(getResources().getString(R.string.txt_viewreport_deletetitle))
|
||||||
public void onClick(View v) {
|
.setMessage(getResources().getString(R.string.txt_viewreport_deletetext))
|
||||||
new AlertDialog.Builder(ViewReportActivity.this)
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> deleteReport(id))
|
||||||
.setTitle(getResources().getString(R.string.txt_viewreport_deletetitle))
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
.setMessage(getResources().getString(R.string.txt_viewreport_deletetext))
|
//do nothing
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
})
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
deleteReport(id);
|
.show());
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
||||||
.show();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Drawable identityIcon = new IconicsDrawable(this)
|
Drawable identityIcon = new IconicsDrawable(this)
|
||||||
.icon(GoogleMaterial.Icon.gmd_account_circle)
|
.icon(GoogleMaterial.Icon.gmd_account_circle)
|
||||||
@@ -158,38 +133,30 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestDeleteIncident(final Integer incidentid) {
|
private StringRequest getStringRequestDeleteIncident(final Integer incidentid) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_DEACTIVATE_INCIDENT, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_DEACTIVATE_INCIDENT, response -> {
|
||||||
|
Log.d(TAG, "Delete Incident with ID response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Delete Incident with ID response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
showMessage(getString(R.string.txt_success_incidentdel));
|
||||||
boolean error = jObj.getBoolean("error");
|
gotoProfileActivity();
|
||||||
|
} else {
|
||||||
if (!error) {
|
String errorMsg = jObj.getString("error_msg");
|
||||||
showMessage(getString(R.string.txt_success_incidentdel));
|
Crashlytics.log(Log.ERROR, TAG, "Error deleting incident (Server returned error): " + errorMsg);
|
||||||
gotoProfileActivity();
|
showMessage(getResources().getString(R.string.txt_errormsg_deleteincident));
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error deleting incident (Server returned error): " + errorMsg);
|
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_deleteincident));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error deleting incident: " + error.getMessage());
|
||||||
@Override
|
handleVolleyErrorResponse();
|
||||||
public void onErrorResponse(VolleyError error) {
|
hideDialog();
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error deleting incident: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -213,41 +180,33 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetIncidentWithPositionFromID(final Integer incidentid) {
|
private StringRequest getStringRequestGetIncidentWithPositionFromID(final Integer incidentid) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENT, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENT, response -> {
|
||||||
|
Log.d(TAG, "Incident with ID response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Incident with ID response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
hideDialog();
|
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject jIncident = jObj.getJSONObject("msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
|
||||||
|
|
||||||
if (!error) {
|
checkVotetypeAndSetVoteButtons(jIncident);
|
||||||
JSONObject jIncident = jObj.getJSONObject("msg");
|
initReport(new IncidentReport(jIncident));
|
||||||
|
|
||||||
checkVotetypeAndSetVoteButtons(jIncident);
|
} else {
|
||||||
initReport(new IncidentReport(jIncident));
|
String errorMsg = jObj.getString("error_msg");
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error get incident (Server returned error): " + errorMsg);
|
||||||
} else {
|
showMessage(getResources().getString(R.string.txt_errormsg_getincidentdetail));
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error get incident (Server returned error): " + errorMsg);
|
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_getincidentdetail));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error get incident: " + error.getMessage());
|
||||||
@Override
|
handleVolleyErrorResponse();
|
||||||
public void onErrorResponse(VolleyError error) {
|
hideDialog();
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error get incident: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -277,74 +236,38 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
btnUpvote.startFlashing(true, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnUpvote.startFlashing(true, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
btnDownvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnDownvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
|
|
||||||
btnUpvote.setOnClickListener(new View.OnClickListener() {
|
btnUpvote.setOnClickListener(v -> deleteVote(incident.getId()));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
deleteVote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnDownvote.setOnClickListener(new View.OnClickListener() {
|
btnDownvote.setOnClickListener(v -> {
|
||||||
@Override
|
deleteVote(incident.getId());
|
||||||
public void onClick(View v) {
|
makeDownvote(incident.getId());
|
||||||
deleteVote(incident.getId());
|
|
||||||
makeDownvote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else if (hasvoted.getInt("fid_votetype") == AppConfig.VOTETYPE_DOWNVOTE) {
|
} else if (hasvoted.getInt("fid_votetype") == AppConfig.VOTETYPE_DOWNVOTE) {
|
||||||
btnUpvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnUpvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
btnDownvote.startFlashing(true, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnDownvote.startFlashing(true, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
|
|
||||||
btnUpvote.setOnClickListener(new View.OnClickListener() {
|
btnUpvote.setOnClickListener(v -> {
|
||||||
@Override
|
deleteVote(incident.getId());
|
||||||
public void onClick(View v) {
|
makeUpvote(incident.getId());
|
||||||
deleteVote(incident.getId());
|
|
||||||
makeUpvote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
btnDownvote.setOnClickListener(new View.OnClickListener() {
|
btnDownvote.setOnClickListener(v -> deleteVote(incident.getId()));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
deleteVote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
btnUpvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnUpvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
btnDownvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnDownvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
|
|
||||||
btnUpvote.setOnClickListener(new View.OnClickListener() {
|
btnUpvote.setOnClickListener(v -> makeUpvote(incident.getId()));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
makeUpvote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnDownvote.setOnClickListener(new View.OnClickListener() {
|
btnDownvote.setOnClickListener(v -> makeDownvote(incident.getId()));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
makeDownvote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
btnUpvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnUpvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
btnDownvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
btnDownvote.startFlashing(false, AwesomeTextView.AnimationSpeed.MEDIUM);
|
||||||
|
|
||||||
btnUpvote.setOnClickListener(new View.OnClickListener() {
|
btnUpvote.setOnClickListener(v -> makeUpvote(incident.getId()));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
makeUpvote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnDownvote.setOnClickListener(new View.OnClickListener() {
|
btnDownvote.setOnClickListener(v -> makeDownvote(incident.getId()));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
makeDownvote(incident.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,19 +328,9 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
final String longitude = Double.toString(incident.getPosition().longitude);
|
final String longitude = Double.toString(incident.getPosition().longitude);
|
||||||
final String fromUid = Integer.toString(incident.getFidFromUser());
|
final String fromUid = Integer.toString(incident.getFidFromUser());
|
||||||
|
|
||||||
findViewById(R.id.btn_viewreport_user).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.btn_viewreport_user).setOnClickListener(v -> gotoProfileActivity(fromUid));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
gotoProfileActivity(fromUid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.btn_viewreport_position).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.btn_viewreport_position).setOnClickListener(v -> gotoMapActivity(latitude + ":" + longitude));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
gotoMapActivity(latitude + ":" + longitude);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
String uid = user.get(SessionManager.KEY_UID);
|
String uid = user.get(SessionManager.KEY_UID);
|
||||||
if (incident.getFidFromUser() != Integer.valueOf(uid)) {
|
if (incident.getFidFromUser() != Integer.valueOf(uid)) {
|
||||||
@@ -448,39 +361,31 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestAddVote(final Integer incidentid, final String votetype) {
|
private StringRequest getStringRequestAddVote(final Integer incidentid, final String votetype) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_ADD_VOTE, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_ADD_VOTE, response -> {
|
||||||
|
Log.d(TAG, "MadeVote: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "MadeVote: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
showMessage(getString(R.string.txt_success_voted));
|
||||||
boolean error = jObj.getBoolean("error");
|
JSONObject jPoints = jObj.getJSONObject("points");
|
||||||
|
|
||||||
if (!error) {
|
scorelabel.setText(String.format(Locale.US, "%d",jPoints.getInt("upvoted") - jPoints.getInt("downvoted")));
|
||||||
showMessage(getString(R.string.txt_success_voted));
|
checkVotetypeAndSetVoteButtons(jPoints);
|
||||||
JSONObject jPoints = jObj.getJSONObject("points");
|
} else {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
scorelabel.setText(String.format("%d",jPoints.getInt("upvoted") - jPoints.getInt("downvoted")));
|
Crashlytics.log(Log.ERROR, TAG, "Error voting incident (Server returned error): " + errorMsg);
|
||||||
checkVotetypeAndSetVoteButtons(jPoints);
|
showMessage(getResources().getString(R.string.txt_errormsg_couldnotvote));
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error voting incident (Server returned error): " + errorMsg);
|
|
||||||
showMessage(getResources().getString(R.string.txt_errormsg_couldnotvote));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error voting incident: " + error.getMessage());
|
||||||
@Override
|
handleVolleyErrorResponse();
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error voting incident: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -503,37 +408,29 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestDeleteVote(final Integer incidentid) {
|
private StringRequest getStringRequestDeleteVote(final Integer incidentid) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_DELETE_VOTE, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_DELETE_VOTE, response -> {
|
||||||
|
Log.d(TAG, "Delete Vote: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Delete Vote: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject jPoints = jObj.getJSONObject("points");
|
||||||
boolean error = jObj.getBoolean("error");
|
|
||||||
|
|
||||||
if (!error) {
|
scorelabel.setText(String.format(Locale.US, "%d", jPoints.getInt("upvoted") - jPoints.getInt("downvoted")));
|
||||||
JSONObject jPoints = jObj.getJSONObject("points");
|
checkVotetypeAndSetVoteButtons(jPoints);
|
||||||
|
} else {
|
||||||
scorelabel.setText(String.format("%d", jPoints.getInt("upvoted") - jPoints.getInt("downvoted")));
|
String errorMsg = jObj.getString("error_msg");
|
||||||
checkVotetypeAndSetVoteButtons(jPoints);
|
Crashlytics.log(Log.ERROR, TAG, "Error deleting voting incident (Server returned error): " + errorMsg);
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error deleting voting incident (Server returned error): " + errorMsg);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error deleting voting incident: " + error.getMessage());
|
||||||
@Override
|
handleVolleyErrorResponse();
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error deleting voting incident: " + error.getMessage());
|
|
||||||
handleVolleyErrorResponse();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class ReportListAdapter extends BaseAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View vi = convertView;
|
View vi = convertView;
|
||||||
if (vi == null) vi = inflater.inflate(R.layout.fragment_reportlist_row, null);
|
if (vi == null) vi = inflater.inflate(R.layout.fragment_reportlist_row, parent, false);
|
||||||
|
|
||||||
TextView itemText = vi.findViewById(R.id.txt_reportlist_lvrow_text);
|
TextView itemText = vi.findViewById(R.id.txt_reportlist_lvrow_text);
|
||||||
TextView titleText = vi.findViewById(R.id.txt_reportlist_lvrow_title);
|
TextView titleText = vi.findViewById(R.id.txt_reportlist_lvrow_title);
|
||||||
@@ -99,7 +99,7 @@ public class ReportListAdapter extends BaseAdapter {
|
|||||||
IncidentReport item = new IncidentReport(data.get(position));
|
IncidentReport item = new IncidentReport(data.get(position));
|
||||||
titleText.setText(item.getIncidentCategoryName(vi.getContext()));
|
titleText.setText(item.getIncidentCategoryName(vi.getContext()));
|
||||||
itemText.setText(item.getIncidentSubCategoryName(vi.getContext()));
|
itemText.setText(item.getIncidentSubCategoryName(vi.getContext()));
|
||||||
itemText.setGravity(Gravity.LEFT);
|
itemText.setGravity(Gravity.START);
|
||||||
itemText.setPadding(0,0,0,0);
|
itemText.setPadding(0,0,0,0);
|
||||||
categoryText.setText(item.getTimeString(vi.getContext()));
|
categoryText.setText(item.getTimeString(vi.getContext()));
|
||||||
|
|
||||||
@@ -111,8 +111,9 @@ public class ReportListAdapter extends BaseAdapter {
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
iv.setBackground(parent.getContext().getDrawable(item.getIconDrawable()));
|
iv.setBackground(parent.getContext().getDrawable(item.getIconDrawable()));
|
||||||
} else {
|
} else {
|
||||||
iv.setBackgroundDrawable(parent.getResources().getDrawable(item.getIconDrawable()));
|
iv.setBackground(parent.getResources().getDrawable(item.getIconDrawable()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return vi;
|
return vi;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class Top10ListAdapter extends BaseAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View vi = convertView;
|
View vi = convertView;
|
||||||
if (vi == null) vi = inflater.inflate(R.layout.fragment_top10list_row, null);
|
if (vi == null) vi = inflater.inflate(R.layout.fragment_top10list_row, parent, false);
|
||||||
|
|
||||||
TextView rank = vi.findViewById(R.id.txt_top10_rank);
|
TextView rank = vi.findViewById(R.id.txt_top10_rank);
|
||||||
TextView name = vi.findViewById(R.id.txt_top10_name);
|
TextView name = vi.findViewById(R.id.txt_top10_name);
|
||||||
@@ -66,13 +66,20 @@ public class Top10ListAdapter extends BaseAdapter {
|
|||||||
TextView points = vi.findViewById(R.id.txt_top10_points);
|
TextView points = vi.findViewById(R.id.txt_top10_points);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rank.setText("#"+data.get(position).getString("rank"));
|
rank.setText(String.format("#%s",
|
||||||
|
data.get(position).getString("rank")));
|
||||||
|
|
||||||
name.setText(data.get(position).getString("username"));
|
name.setText(data.get(position).getString("username"));
|
||||||
name.setTypeface(null, Typeface.BOLD);
|
name.setTypeface(null, Typeface.BOLD);
|
||||||
points.setText(data.get(position).getString("points"));
|
points.setText(data.get(position).getString("points"));
|
||||||
|
|
||||||
numberOfIncidents.setText(data.get(position).getString("numberOfPosts")+" "+context.getResources().getString(R.string.txt_top10_reportedinc));
|
numberOfIncidents.setText(String.format("%s %s",
|
||||||
memberSince.setText(context.getResources().getString(R.string.txt_top10_membersince)+" "+data.get(position).getString("created_at").split(" ")[0]);
|
data.get(position).getString("numberOfPosts"),
|
||||||
|
context.getResources().getString(R.string.txt_top10_reportedinc)));
|
||||||
|
|
||||||
|
memberSince.setText(String.format("%s %s",
|
||||||
|
context.getResources().getString(R.string.txt_top10_membersince),
|
||||||
|
data.get(position).getString("created_at").split(" ")[0]));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
Crashlytics.logException(e);
|
Crashlytics.logException(e);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.deke.risk.riskahead.fragment;
|
package org.deke.risk.riskahead.fragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import android.support.v4.app.Fragment;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
@@ -19,7 +18,6 @@ import com.facebook.CallbackManager;
|
|||||||
import com.facebook.FacebookCallback;
|
import com.facebook.FacebookCallback;
|
||||||
import com.facebook.FacebookException;
|
import com.facebook.FacebookException;
|
||||||
import com.facebook.GraphRequest;
|
import com.facebook.GraphRequest;
|
||||||
import com.facebook.GraphResponse;
|
|
||||||
import com.facebook.login.LoginBehavior;
|
import com.facebook.login.LoginBehavior;
|
||||||
import com.facebook.login.LoginManager;
|
import com.facebook.login.LoginManager;
|
||||||
import com.facebook.login.LoginResult;
|
import com.facebook.login.LoginResult;
|
||||||
@@ -27,7 +25,6 @@ import com.facebook.login.LoginResult;
|
|||||||
import org.deke.risk.riskahead.LoginActivity;
|
import org.deke.risk.riskahead.LoginActivity;
|
||||||
import org.deke.risk.riskahead.R;
|
import org.deke.risk.riskahead.R;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -84,23 +81,16 @@ public class FacebookButtonFragment extends Fragment {
|
|||||||
mListener = null;
|
mListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnFragmentInteractionListener {
|
|
||||||
void onFragmentInteraction(Uri uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initFacebookButton() {
|
private void initFacebookButton() {
|
||||||
BootstrapButton btnLoginFB = view.findViewById(R.id.btn_login_fb);
|
BootstrapButton btnLoginFB = view.findViewById(R.id.btn_login_fb);
|
||||||
|
|
||||||
btnLoginFB.setOnClickListener(new OnClickListener() {
|
btnLoginFB.setOnClickListener(v -> {
|
||||||
@Override
|
LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY);
|
||||||
public void onClick(View v) {
|
Activity activity = getActivity();
|
||||||
LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY);
|
if(activity != null){
|
||||||
Activity activity = getActivity();
|
LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("public_profile", "email"));
|
||||||
if(activity != null){
|
}else{
|
||||||
LoginManager.getInstance().logInWithReadPermissions(activity, Arrays.asList("public_profile", "email"));
|
Crashlytics.log(Log.ERROR, TAG, "Could not get activity when initializing the facebook button");
|
||||||
}else{
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not get activity when initializing the facebook button");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -136,20 +126,17 @@ public class FacebookButtonFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getUserMailAndLogin(AccessToken accesstoken){
|
private void getUserMailAndLogin(AccessToken accesstoken){
|
||||||
GraphRequest request = GraphRequest.newMeRequest(accesstoken, new GraphRequest.GraphJSONObjectCallback() {
|
GraphRequest request = GraphRequest.newMeRequest(accesstoken, (objects, response) -> {
|
||||||
@Override
|
try {
|
||||||
public void onCompleted(JSONObject objects, GraphResponse response) {
|
LoginActivity activity = (LoginActivity) getActivity();
|
||||||
try {
|
if(activity != null){
|
||||||
LoginActivity activity = (LoginActivity) getActivity();
|
activity.handleSocialMediaLogin(objects.getString("id"), "facebook", objects.getString("first_name"), objects.getString("email"));
|
||||||
if(activity != null){
|
}else{
|
||||||
activity.handleSocialMediaLogin(objects.getString("id"), "facebook", objects.getString("first_name"), objects.getString("email"));
|
Crashlytics.log(Log.ERROR, TAG, "Could not get activity for handleSocialMediaLogin");
|
||||||
}else{
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not get activity for handleSocialMediaLogin");
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Exception caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Exception caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Bundle parameters = new Bundle();
|
Bundle parameters = new Bundle();
|
||||||
@@ -157,4 +144,8 @@ public class FacebookButtonFragment extends Fragment {
|
|||||||
request.setParameters(parameters);
|
request.setParameters(parameters);
|
||||||
request.executeAsync();
|
request.executeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OnFragmentInteractionListener {
|
||||||
|
void onFragmentInteraction(Uri uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -51,16 +52,11 @@ public class GooglePlusButtonFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_googleplus_button,container, false);
|
View view = inflater.inflate(R.layout.fragment_googleplus_button,container, false);
|
||||||
|
|
||||||
BootstrapButton btnSignIn = view.findViewById(R.id.btn_login_gp);
|
BootstrapButton btnSignIn = view.findViewById(R.id.btn_login_gp);
|
||||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
btnSignIn.setOnClickListener(v -> performClickAction());
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
performClickAction();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.deke.risk.riskahead.fragment;
|
package org.deke.risk.riskahead.fragment;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -9,13 +10,10 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
|
import com.beardedhen.androidbootstrap.api.defaults.DefaultBootstrapBrand;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.Crashlytics;
|
|
||||||
|
|
||||||
import org.deke.risk.riskahead.ProfileActivity;
|
import org.deke.risk.riskahead.ProfileActivity;
|
||||||
import org.deke.risk.riskahead.R;
|
import org.deke.risk.riskahead.R;
|
||||||
@@ -56,7 +54,7 @@ public class ProfileStatisticsFragment extends Fragment {
|
|||||||
private BootstrapButton btnMembershipType;
|
private BootstrapButton btnMembershipType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_profile_stats, container, false);
|
View view = inflater.inflate(R.layout.fragment_profile_stats, container, false);
|
||||||
parent = (ProfileActivity)getActivity();
|
parent = (ProfileActivity)getActivity();
|
||||||
|
|
||||||
@@ -97,94 +95,86 @@ public class ProfileStatisticsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestProfileStats() {
|
private StringRequest getStringRequestProfileStats() {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_USERSTATS, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_USERSTATS, response -> {
|
||||||
|
Log.d(TAG, "User stats: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "User stats: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
if (!error && isAdded()) {
|
||||||
|
posts.setText(jObj.getString("numberOfPosts"));
|
||||||
|
|
||||||
try {
|
JSONObject subJObj = jObj.getJSONObject("msg");
|
||||||
JSONObject jObj = new JSONObject(response);
|
points.setText(subJObj.getString("points"));
|
||||||
boolean error = jObj.getBoolean("error");
|
ranking.setText(subJObj.getString("rank"));
|
||||||
if (!error) {
|
txtMemberSince.setText(subJObj.getString("created_at"));
|
||||||
posts.setText(jObj.getString("numberOfPosts"));
|
|
||||||
|
|
||||||
JSONObject subJObj = jObj.getJSONObject("msg");
|
JSONArray jSubs = jObj.getJSONArray("subs");
|
||||||
points.setText(subJObj.getString("points"));
|
|
||||||
ranking.setText(subJObj.getString("rank"));
|
|
||||||
txtMemberSince.setText(subJObj.getString("created_at"));
|
|
||||||
|
|
||||||
JSONArray jSubs = jObj.getJSONArray("subs");
|
if(jSubs.length() == 0){
|
||||||
|
btnMembershipType.setBootstrapBrand(DefaultBootstrapBrand.SUCCESS);
|
||||||
|
btnMembershipType.setText(getResources().getString(R.string.lbl_membershiptype_free));
|
||||||
|
}else{
|
||||||
|
boolean no_ads = false;
|
||||||
|
boolean premium = false;
|
||||||
|
|
||||||
if(jSubs.length() == 0){
|
for(int i = 0; i < jSubs.length();i++) {
|
||||||
btnMembershipType.setBootstrapBrand(DefaultBootstrapBrand.SUCCESS);
|
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
||||||
btnMembershipType.setText(getResources().getString(R.string.lbl_membershiptype_free));
|
no_ads = true;
|
||||||
}else{
|
|
||||||
boolean no_ads = false;
|
|
||||||
boolean premium = false;
|
|
||||||
|
|
||||||
for(int i = 0; i < jSubs.length();i++) {
|
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
|
||||||
no_ads = true;
|
|
||||||
}
|
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
|
||||||
premium = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
||||||
|
premium = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProfileActivity activity = (ProfileActivity) getActivity();
|
ProfileActivity activity = (ProfileActivity) getActivity();
|
||||||
if(activity != null){
|
if(activity != null){
|
||||||
if(no_ads){
|
if(no_ads){
|
||||||
btnMembershipType.setBootstrapBrand(DefaultBootstrapBrand.PRIMARY);
|
btnMembershipType.setBootstrapBrand(DefaultBootstrapBrand.PRIMARY);
|
||||||
btnMembershipType.setText(getResources().getString(R.string.lbl_membershiptype_addfree));
|
btnMembershipType.setText(getResources().getString(R.string.lbl_membershiptype_addfree));
|
||||||
activity.session.setSubsNoAds(true);
|
activity.session.setSubsNoAds(true);
|
||||||
}else{
|
|
||||||
activity.session.setSubsNoAds(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(premium){
|
|
||||||
btnMembershipType.setBootstrapBrand(DefaultBootstrapBrand.WARNING);
|
|
||||||
btnMembershipType.setText(getResources().getString(R.string.lbl_membershiptype_premium));
|
|
||||||
activity.session.setSubsPremium(true);
|
|
||||||
}else{
|
|
||||||
activity.session.setSubsPremium(false);
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not retrieve activity for ProfileStatistics. Could not set statusLevel");
|
activity.session.setSubsNoAds(false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(!parent.user.get(SessionManager.KEY_UID).equals(uid) ){
|
if(premium){
|
||||||
lblPoints.setText(jObj.getString("username")+" "+getResources().getString(R.string.lbl_profile_points_someone));
|
btnMembershipType.setBootstrapBrand(DefaultBootstrapBrand.WARNING);
|
||||||
lblPosts.setText(getResources().getString(R.string.lbl_profile_numofposts_me));
|
btnMembershipType.setText(getResources().getString(R.string.lbl_membershiptype_premium));
|
||||||
lblRanking.setText(getResources().getString(R.string.lbl_profile_ranking_someone));
|
activity.session.setSubsPremium(true);
|
||||||
lblMemberSince.setText(jObj.getString("username")+" "+getResources().getString(R.string.lbl_profile_membersince_someone));
|
}else{
|
||||||
|
activity.session.setSubsPremium(false);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Could not retrieve activity for ProfileStatistics. Could not set statusLevel");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting user stats (server returned error): " + errorMsg);
|
|
||||||
|
|
||||||
parent.showMessage(getResources().getString(R.string.txt_errormsg_retrievestats));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
((ProfileActivity)getActivity()).hideDialog();
|
if(!parent.user.get(SessionManager.KEY_UID).equals(uid) ){
|
||||||
} catch (JSONException e) {
|
lblPoints.setText(String.format("%s %s", jObj.getString("username"), getResources().getString(R.string.lbl_profile_points_someone)));
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
lblPosts.setText(getResources().getString(R.string.lbl_profile_numofposts_me));
|
||||||
Crashlytics.logException(e);
|
lblRanking.setText(getResources().getString(R.string.lbl_profile_ranking_someone));
|
||||||
}
|
lblMemberSince.setText(String.format("%s %s",jObj.getString("username"), getResources().getString(R.string.lbl_profile_membersince_someone)));
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
} else {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting user stats (server returned error): " + errorMsg);
|
||||||
|
|
||||||
@Override
|
parent.showMessage(getResources().getString(R.string.txt_errormsg_retrievestats));
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting user stats: " + error.getMessage());
|
|
||||||
ProfileActivity activity = (ProfileActivity) getActivity();
|
|
||||||
if(activity != null){
|
|
||||||
activity.hideDialog();
|
|
||||||
activity.handleVolleyErrorResponse();
|
|
||||||
}else {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not retrieve activity for onErrorResponse");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((ProfileActivity)getActivity()).hideDialog();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting user stats: " + error.getMessage());
|
||||||
|
ProfileActivity activity = (ProfileActivity) getActivity();
|
||||||
|
if(activity != null){
|
||||||
|
activity.hideDialog();
|
||||||
|
activity.handleVolleyErrorResponse();
|
||||||
|
}else {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Could not retrieve activity for onErrorResponse");
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
package org.deke.risk.riskahead.fragment;
|
package org.deke.risk.riskahead.fragment;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.crashlytics.android.Crashlytics;
|
|
||||||
|
|
||||||
import org.deke.risk.riskahead.ProfileActivity;
|
import org.deke.risk.riskahead.ProfileActivity;
|
||||||
import org.deke.risk.riskahead.R;
|
import org.deke.risk.riskahead.R;
|
||||||
@@ -51,7 +48,7 @@ public class ReportListFragment extends Fragment{
|
|||||||
private String uid;
|
private String uid;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_reportlist, container, false);
|
View view = inflater.inflate(R.layout.fragment_reportlist, container, false);
|
||||||
|
|
||||||
parent = (ProfileActivity)getActivity();
|
parent = (ProfileActivity)getActivity();
|
||||||
@@ -66,17 +63,14 @@ public class ReportListFragment extends Fragment{
|
|||||||
|
|
||||||
if(resultList == null || resultList.size() == 0) getIncidentsForList();
|
if(resultList == null || resultList.size() == 0) getIncidentsForList();
|
||||||
|
|
||||||
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
myListView.setOnItemClickListener((parentview, view1, position, id) -> {
|
||||||
@Override
|
try {
|
||||||
public void onItemClick(AdapterView<?> parentview, View view, int position, long id) {
|
if(resultList.get(position).getInt("status") == 1){
|
||||||
try {
|
parent.gotoViewReportActivity(resultList.get(position).getInt("id"));
|
||||||
if(resultList.get(position).getInt("status") == 1){
|
|
||||||
parent.gotoViewReportActivity(resultList.get(position).getInt("id"));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Catched JSONException");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Catched JSONException");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -97,56 +91,48 @@ public class ReportListFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetIncidentsWithPositionFromUserID() {
|
private StringRequest getStringRequestGetIncidentsWithPositionFromUserID() {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMUSERID, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMUSERID, response -> {
|
||||||
|
Log.d(TAG, "Map positions response with ID: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Map positions response with ID: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONArray incidents = jObj.getJSONArray("msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
resultList = new ArrayList<>();
|
||||||
|
|
||||||
if (!error) {
|
for(int i=0;i<incidents.length();i++){
|
||||||
JSONArray incidents = jObj.getJSONArray("msg");
|
|
||||||
resultList = new ArrayList<>();
|
|
||||||
|
|
||||||
for(int i=0;i<incidents.length();i++){
|
JSONObject incident = incidents.getJSONObject(i);
|
||||||
|
resultList.add(incident);
|
||||||
JSONObject incident = incidents.getJSONObject(i);
|
|
||||||
resultList.add(incident);
|
|
||||||
}
|
|
||||||
|
|
||||||
myListAdapter = new ReportListAdapter(
|
|
||||||
parent.getApplicationContext(),
|
|
||||||
resultList);
|
|
||||||
|
|
||||||
myListView.setAdapter(myListAdapter);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting incident list (Server returned error): " + errorMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileActivity activity = (ProfileActivity) getActivity();
|
myListAdapter = new ReportListAdapter(
|
||||||
if(activity != null){
|
parent.getApplicationContext(),
|
||||||
activity.hideDialog();
|
resultList);
|
||||||
}else{
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not get parent activity");
|
myListView.setAdapter(myListAdapter);
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
} else {
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Catched JSONException");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Crashlytics.logException(e);
|
Crashlytics.log(Log.ERROR, TAG, "Error getting incident list (Server returned error): " + errorMsg);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
ProfileActivity activity = (ProfileActivity) getActivity();
|
||||||
public void onErrorResponse(VolleyError error) {
|
if(activity != null){
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting incident list: " + error.getMessage());
|
activity.hideDialog();
|
||||||
parent.handleVolleyErrorResponse();
|
}else{
|
||||||
parent.hideDialog();
|
Crashlytics.log(Log.ERROR, TAG, "Could not get parent activity");
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Catched JSONException");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting incident list: " + error.getMessage());
|
||||||
|
parent.handleVolleyErrorResponse();
|
||||||
|
parent.hideDialog();
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -160,5 +146,4 @@ public class ReportListFragment extends Fragment{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.deke.risk.riskahead.fragment;
|
|||||||
|
|
||||||
import android.app.DatePickerDialog;
|
import android.app.DatePickerDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.app.TimePickerDialog;
|
import android.app.TimePickerDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -205,52 +206,46 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
|
|||||||
inputDateFrom = viewFragment.findViewById(R.id.input_report_from_date);
|
inputDateFrom = viewFragment.findViewById(R.id.input_report_from_date);
|
||||||
inputTimeFrom = viewFragment.findViewById(R.id.input_report_from_time);
|
inputTimeFrom = viewFragment.findViewById(R.id.input_report_from_time);
|
||||||
|
|
||||||
inputDateFrom.setOnClickListener(new View.OnClickListener() {
|
inputDateFrom.setOnClickListener(v -> {
|
||||||
@Override
|
tmpInput = inputDateFrom;
|
||||||
public void onClick(View v) {
|
tmpInput.addTextChangedListener(new TextWatcher() {
|
||||||
tmpInput = inputDateFrom;
|
@Override
|
||||||
tmpInput.addTextChangedListener(new TextWatcher() {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
checkIfFinished();
|
checkIfFinished();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
showDatePickerDialog();
|
showDatePickerDialog();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
inputTimeFrom.setOnClickListener(new View.OnClickListener() {
|
inputTimeFrom.setOnClickListener(v -> {
|
||||||
@Override
|
tmpInput = inputTimeFrom;
|
||||||
public void onClick(View v) {
|
tmpInput.addTextChangedListener(new TextWatcher() {
|
||||||
tmpInput = inputTimeFrom;
|
@Override
|
||||||
tmpInput.addTextChangedListener(new TextWatcher() {
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
checkIfFinished();
|
checkIfFinished();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
showTimePickerDialog();
|
showTimePickerDialog();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,28 +256,23 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
|
|||||||
inputDateTo = viewFragment.findViewById(R.id.input_report_to_date);
|
inputDateTo = viewFragment.findViewById(R.id.input_report_to_date);
|
||||||
inputTimeTo = viewFragment.findViewById(R.id.input_report_to_time);
|
inputTimeTo = viewFragment.findViewById(R.id.input_report_to_time);
|
||||||
|
|
||||||
inputDateTo.setOnClickListener(new View.OnClickListener() {
|
inputDateTo.setOnClickListener(v -> {
|
||||||
@Override
|
tmpInput = inputDateTo;
|
||||||
public void onClick(View v) {
|
tmpIsToDate = true;
|
||||||
tmpInput = inputDateTo;
|
showDatePickerDialog();
|
||||||
tmpIsToDate = true;
|
|
||||||
showDatePickerDialog();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
inputTimeTo.setOnClickListener(new View.OnClickListener() {
|
inputTimeTo.setOnClickListener(v -> {
|
||||||
@Override
|
tmpInput = inputTimeTo;
|
||||||
public void onClick(View v) {
|
tmpIsToTime = true;
|
||||||
tmpInput = inputTimeTo;
|
showTimePickerDialog();
|
||||||
tmpIsToTime = true;
|
|
||||||
showTimePickerDialog();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
|
public static class TimePickerFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
int hour = c.get(Calendar.HOUR_OF_DAY);
|
int hour = c.get(Calendar.HOUR_OF_DAY);
|
||||||
@@ -314,6 +304,7 @@ public class ReportWF_2_Fragment extends BaseReportWFFragment {
|
|||||||
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
|
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
int year = c.get(Calendar.YEAR);
|
int year = c.get(Calendar.YEAR);
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.deke.risk.riskahead.helper.IncidentReport;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ReportWF_Finish_Fragment extends BaseReportWFFragment {
|
public class ReportWF_Finish_Fragment extends BaseReportWFFragment {
|
||||||
|
|
||||||
private final static String TAG = ReportWF_Finish_Fragment.class.getSimpleName();
|
private final static String TAG = ReportWF_Finish_Fragment.class.getSimpleName();
|
||||||
|
|
||||||
private SendReportListener mCallback;
|
private SendReportListener mCallback;
|
||||||
@@ -33,12 +32,7 @@ public class ReportWF_Finish_Fragment extends BaseReportWFFragment {
|
|||||||
View viewFragment = inflater.inflate(R.layout.fragment_reportwf_finish, container, false);
|
View viewFragment = inflater.inflate(R.layout.fragment_reportwf_finish, container, false);
|
||||||
|
|
||||||
Button btnSendReport = viewFragment.findViewById(R.id.btn_reportwf_finish_send);
|
Button btnSendReport = viewFragment.findViewById(R.id.btn_reportwf_finish_send);
|
||||||
btnSendReport.setOnClickListener(new View.OnClickListener() {
|
btnSendReport.setOnClickListener(v -> mCallback.sendReport());
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
mCallback.sendReport();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return viewFragment;
|
return viewFragment;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.deke.risk.riskahead.fragment;
|
package org.deke.risk.riskahead.fragment;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.EditTextPreference;
|
import android.preference.EditTextPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
@@ -11,8 +10,6 @@ import android.support.v7.app.AlertDialog;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
@@ -76,68 +73,53 @@ public class SettingsFragment extends PreferenceFragment {
|
|||||||
prefGPSENabled = (SwitchPreference) getPreferenceManager().findPreference("notifyEnableGPS");
|
prefGPSENabled = (SwitchPreference) getPreferenceManager().findPreference("notifyEnableGPS");
|
||||||
prefLocation = getPreferenceManager().findPreference("notifyChooseLocation");
|
prefLocation = getPreferenceManager().findPreference("notifyChooseLocation");
|
||||||
|
|
||||||
prefNotifications.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
prefNotifications.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@Override
|
String newStringValue = newValue.toString();
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
session.setNotificationEnabled(Boolean.valueOf(newStringValue));
|
||||||
String newStringValue = newValue.toString();
|
return true;
|
||||||
session.setNotificationEnabled(Boolean.valueOf(newStringValue));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
prefRadius.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
prefRadius.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@Override
|
String newStringValue = newValue.toString();
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
String newStringValue = newValue.toString();
|
|
||||||
|
|
||||||
if(session.getSubsPremium() || Integer.valueOf(newStringValue) < 25){
|
if(session.getSubsPremium() || Integer.valueOf(newStringValue) < 25){
|
||||||
session.setNotificationRadius(Integer.valueOf(newStringValue));
|
session.setNotificationRadius(Integer.valueOf(newStringValue));
|
||||||
((ListPreference) preference).setValue(newValue.toString());
|
|
||||||
preference.setSummary(prefRadius.getEntry());
|
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
((SettingsActivity) getActivity()).showMessage(getString(R.string.txt_premium_only));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
prefFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
String newStringValue = newValue.toString();
|
|
||||||
session.setNotificationPollFreq(Integer.valueOf(newStringValue));
|
|
||||||
((ListPreference) preference).setValue(newValue.toString());
|
((ListPreference) preference).setValue(newValue.toString());
|
||||||
preference.setSummary(prefFrequency.getEntry());
|
preference.setSummary(prefRadius.getEntry());
|
||||||
return true;
|
return true;
|
||||||
|
}else{
|
||||||
|
((SettingsActivity) getActivity()).showMessage(getString(R.string.txt_premium_only));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
prefGPSENabled.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
|
||||||
@Override
|
prefFrequency.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
String newStringValue = newValue.toString();
|
||||||
String newStringValue = newValue.toString();
|
session.setNotificationPollFreq(Integer.valueOf(newStringValue));
|
||||||
session.setGPSForNotificationsEnabled(Boolean.valueOf(newStringValue));
|
((ListPreference) preference).setValue(newValue.toString());
|
||||||
updatePrefs();
|
preference.setSummary(prefFrequency.getEntry());
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
prefLocation.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
prefGPSENabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@Override
|
String newStringValue = newValue.toString();
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
session.setGPSForNotificationsEnabled(Boolean.valueOf(newStringValue));
|
||||||
if (session.getManualLocation().longitude != 0.0 && session.getManualLocation().latitude != 0.0) {
|
updatePrefs();
|
||||||
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity(Double.toString(session.getManualLocation().latitude) + " : " + Double.toString(session.getManualLocation().longitude));
|
return true;
|
||||||
} else if(session.getLocation().longitude != 0.0 && session.getLocation().latitude != 0.0){
|
});
|
||||||
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity(Double.toString(session.getLocation().latitude) + " : " + Double.toString(session.getLocation().longitude));
|
|
||||||
} else {
|
|
||||||
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
prefLocation.setOnPreferenceClickListener(preference -> {
|
||||||
|
if (session.getManualLocation().longitude != 0.0 && session.getManualLocation().latitude != 0.0) {
|
||||||
|
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity(Double.toString(session.getManualLocation().latitude) + " : " + Double.toString(session.getManualLocation().longitude));
|
||||||
|
} else if(session.getLocation().longitude != 0.0 && session.getLocation().latitude != 0.0){
|
||||||
|
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity(Double.toString(session.getLocation().latitude) + " : " + Double.toString(session.getLocation().longitude));
|
||||||
|
} else {
|
||||||
|
((SettingsActivity) getActivity()).getNotifyLocationFromMapActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!session.getSubsPremium()){
|
if(!session.getSubsPremium()){
|
||||||
@@ -158,12 +140,9 @@ public class SettingsFragment extends PreferenceFragment {
|
|||||||
prefEmail = (ValidatedEditTextPreference) getPreferenceManager().findPreference("emailPref");
|
prefEmail = (ValidatedEditTextPreference) getPreferenceManager().findPreference("emailPref");
|
||||||
Preference btnRequestPW = getPreferenceManager().findPreference("resetPassword");
|
Preference btnRequestPW = getPreferenceManager().findPreference("resetPassword");
|
||||||
|
|
||||||
Preference.OnPreferenceChangeListener changeListener = new Preference.OnPreferenceChangeListener() {
|
Preference.OnPreferenceChangeListener changeListener = (preference, newValue) -> {
|
||||||
@Override
|
requestUpdateUserSettings(preference,newValue.toString());
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
return true;
|
||||||
requestUpdateUserSettings(preference,newValue.toString());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
prefUsername.setOnPreferenceChangeListener(changeListener);
|
prefUsername.setOnPreferenceChangeListener(changeListener);
|
||||||
@@ -172,27 +151,18 @@ public class SettingsFragment extends PreferenceFragment {
|
|||||||
prefEmail.setOnPreferenceChangeListener(changeListener);
|
prefEmail.setOnPreferenceChangeListener(changeListener);
|
||||||
|
|
||||||
if(btnRequestPW != null){
|
if(btnRequestPW != null){
|
||||||
btnRequestPW.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
btnRequestPW.setOnPreferenceClickListener(preference -> {
|
||||||
@Override
|
new AlertDialog.Builder(getActivity())
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
.setTitle(getResources().getString(R.string.txt_settings_resetpwtitle))
|
||||||
new AlertDialog.Builder(getActivity())
|
.setMessage(getResources().getString(R.string.txt_settings_resetpwtext))
|
||||||
.setTitle(getResources().getString(R.string.txt_settings_resetpwtitle))
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> requestPasswordReset())
|
||||||
.setMessage(getResources().getString(R.string.txt_settings_resetpwtext))
|
.setNegativeButton(android.R.string.no, (dialog, which) -> {
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
// do nothing
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
})
|
||||||
requestPasswordReset();
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
}
|
.show();
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
||||||
.show();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(!user.get(SessionManager.PROVIDER_TYPE).equals("local")){
|
if(!user.get(SessionManager.PROVIDER_TYPE).equals("local")){
|
||||||
@@ -243,38 +213,30 @@ public class SettingsFragment extends PreferenceFragment {
|
|||||||
|
|
||||||
private StringRequest getStringRequestResetPW(final String email) {
|
private StringRequest getStringRequestResetPW(final String email) {
|
||||||
((SettingsActivity) getActivity()).showDialog();
|
((SettingsActivity) getActivity()).showDialog();
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_REQUESTPWRESET, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_REQUESTPWRESET, response -> {
|
||||||
|
Log.d(TAG, "Resend E-Mail Response: " + response);
|
||||||
|
((SettingsActivity) getActivity()).hideDialog();
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Resend E-Mail Response: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
((SettingsActivity) getActivity()).hideDialog();
|
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
((SettingsActivity) getActivity()).showMessage(getString(R.string.alert_passwordreset_confirmation));
|
||||||
boolean error = jObj.getBoolean("error");
|
}else{
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
if (!error) {
|
Crashlytics.log(Log.ERROR, TAG, "Error request email reset (Server returned error): " + errorMsg);
|
||||||
((SettingsActivity) getActivity()).showMessage(getString(R.string.alert_passwordreset_confirmation));
|
((SettingsActivity) getActivity()).showMessage(getResources().getString(R.string.txt_errormsg_resetpw));
|
||||||
}else{
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error request email reset (Server returned error): " + errorMsg);
|
|
||||||
((SettingsActivity) getActivity()).showMessage(getResources().getString(R.string.txt_errormsg_resetpw));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
}, error -> {
|
||||||
public void onErrorResponse(VolleyError error) {
|
Crashlytics.log(Log.ERROR, TAG, "Error request email reset: " + error.getMessage());
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error request email reset: " + error.getMessage());
|
((SettingsActivity) getActivity()).showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
((SettingsActivity) getActivity()).showMessage(getString(R.string.errormsg_couldnotretrieve));
|
((SettingsActivity) getActivity()).hideDialog();
|
||||||
((SettingsActivity) getActivity()).hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -291,79 +253,75 @@ public class SettingsFragment extends PreferenceFragment {
|
|||||||
((SettingsActivity) getActivity()).showDialog();
|
((SettingsActivity) getActivity()).showDialog();
|
||||||
String username = prefUsername.getText(),name = prefName.getText(),surname = prefSurname.getText(),email = prefEmail.getText();
|
String username = prefUsername.getText(),name = prefName.getText(),surname = prefSurname.getText(),email = prefEmail.getText();
|
||||||
|
|
||||||
if(pref.getKey().equals("usernamePref")){
|
switch (pref.getKey()){
|
||||||
username = newValue;
|
case "usernamePref":
|
||||||
}else if(pref.getKey().equals("namePref")){
|
username = newValue;
|
||||||
name = newValue;
|
break;
|
||||||
}else if(pref.getKey().equals("surnamePref")){
|
case "namePref":
|
||||||
surname = newValue;
|
name = newValue;
|
||||||
}else if(pref.getKey().equals("emailPref")){
|
break;
|
||||||
email = newValue;
|
case "surnamePref":
|
||||||
|
surname = newValue;
|
||||||
|
break;
|
||||||
|
case "emailPref":
|
||||||
|
email = newValue;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String tag_string_req = "updateuser";
|
String tag_string_req = "updateuser";
|
||||||
StringRequest strReq = getStringChangeUserSettings(username,name,surname,email);
|
StringRequest strReq = getStringChangeUserSettings(username,name,surname,email);
|
||||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringChangeUserSettings(final String username, final String name, final String surname, final String email) {
|
private StringRequest getStringChangeUserSettings(final String username, final String name, final String surname, final String email) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_UPDATE_USER, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_UPDATE_USER, response -> {
|
||||||
|
Log.d(TAG, "Change user settings: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Change user settings: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
if (!error) {
|
||||||
|
((SettingsActivity) getActivity()).showMessage(getResources().getString(R.string.txt_success_changesett));
|
||||||
|
JSONObject tmpuser = jObj.getJSONObject("user");
|
||||||
|
|
||||||
try {
|
JSONArray jSubs = tmpuser.getJSONArray("subs");
|
||||||
JSONObject jObj = new JSONObject(response);
|
boolean isPremium = false;
|
||||||
boolean error = jObj.getBoolean("error");
|
boolean isAdFree = false;
|
||||||
if (!error) {
|
|
||||||
((SettingsActivity) getActivity()).showMessage(getResources().getString(R.string.txt_success_changesett));
|
|
||||||
JSONObject tmpuser = jObj.getJSONObject("user");
|
|
||||||
|
|
||||||
JSONArray jSubs = tmpuser.getJSONArray("subs");
|
if(jSubs.length() > 0){
|
||||||
boolean isPremium = false;
|
for(int i = 0; i < jSubs.length();i++) {
|
||||||
boolean isAdFree = false;
|
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
||||||
|
isPremium = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(jSubs.length() > 0){
|
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
||||||
for(int i = 0; i < jSubs.length();i++) {
|
isAdFree = true;
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("extra_functions")){
|
|
||||||
isPremium = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(jSubs.getJSONObject(i).getString("productId").contains("no_ads")){
|
|
||||||
isAdFree = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
((SettingsActivity) getActivity()).session.addUser(tmpuser.getString("id"), tmpuser.getString("username"), tmpuser.getString("name"), tmpuser.getString("surname"), tmpuser.getString("email"), tmpuser.getString("status"), user.get("providerType"), tmpuser.getString("created_at"), tmpuser.getString("updated_at"), tmpuser.getString("lastlogin_at"), tmpuser.getString("accesskey"),isPremium,isAdFree);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting user settings (Server returned error): " + errorMsg);
|
|
||||||
((SettingsActivity) getActivity()).showMessage(getResources().getString(R.string.txt_errormsg_changesettings));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (JSONException e) {
|
((SettingsActivity) getActivity()).session.addUser(tmpuser.getString("id"), tmpuser.getString("username"), tmpuser.getString("name"), tmpuser.getString("surname"), tmpuser.getString("email"), tmpuser.getString("status"), user.get("providerType"), tmpuser.getString("created_at"), tmpuser.getString("updated_at"), tmpuser.getString("lastlogin_at"), tmpuser.getString("accesskey"),isPremium,isAdFree);
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
} else {
|
||||||
} finally {
|
String errorMsg = jObj.getString("error_msg");
|
||||||
updatePrefs();
|
Crashlytics.log(Log.ERROR, TAG, "Error getting user settings (Server returned error): " + errorMsg);
|
||||||
|
((SettingsActivity) getActivity()).showMessage(getResources().getString(R.string.txt_errormsg_changesettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
((SettingsActivity) getActivity()).hideDialog();
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
}
|
Crashlytics.logException(e);
|
||||||
}, new Response.ErrorListener() {
|
} finally {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting user settings: " + error.getMessage());
|
|
||||||
((SettingsActivity) getActivity()).showMessage(getString(R.string.errormsg_couldnotretrieve));
|
|
||||||
((SettingsActivity) getActivity()).hideDialog();
|
|
||||||
updatePrefs();
|
updatePrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
((SettingsActivity) getActivity()).hideDialog();
|
||||||
|
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting user settings: " + error.getMessage());
|
||||||
|
((SettingsActivity) getActivity()).showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
|
((SettingsActivity) getActivity()).hideDialog();
|
||||||
|
updatePrefs();
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.deke.risk.riskahead.fragment;
|
package org.deke.risk.riskahead.fragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -37,7 +38,7 @@ public class SubscriptionItemFragment extends Fragment {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_subscriptionitem, container, false);
|
View view = inflater.inflate(R.layout.fragment_subscriptionitem, container, false);
|
||||||
parent = (SubscriptionsActivity)getActivity();
|
parent = (SubscriptionsActivity)getActivity();
|
||||||
|
|
||||||
@@ -81,12 +82,9 @@ public class SubscriptionItemFragment extends Fragment {
|
|||||||
txtDescription.setText(description);
|
txtDescription.setText(description);
|
||||||
btnPurchase.setText(price);
|
btnPurchase.setText(price);
|
||||||
|
|
||||||
btnPurchase.setOnClickListener(new View.OnClickListener() {
|
btnPurchase.setOnClickListener(v -> {
|
||||||
@Override
|
Log.d(TAG, "PURCHASE: " + id);
|
||||||
public void onClick(View v) {
|
parent.buyProduct(id);
|
||||||
Log.d(TAG, "PURCHASE: " + id);
|
|
||||||
parent.buyProduct(id);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
txtTitle.setVisibility(View.VISIBLE);
|
txtTitle.setVisibility(View.VISIBLE);
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
package org.deke.risk.riskahead.fragment;
|
package org.deke.risk.riskahead.fragment;
|
||||||
|
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
|
|
||||||
@@ -48,21 +46,18 @@ public class Top10Fragment extends Fragment {
|
|||||||
List<JSONObject> resultList;
|
List<JSONObject> resultList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_top10list, container, false);
|
View view = inflater.inflate(R.layout.fragment_top10list, container, false);
|
||||||
parent = (ProfileActivity)getActivity();
|
parent = (ProfileActivity)getActivity();
|
||||||
|
|
||||||
myListView = view.findViewById(R.id.lv_top10list);
|
myListView = view.findViewById(R.id.lv_top10list);
|
||||||
|
|
||||||
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
myListView.setOnItemClickListener((parentview, view1, position, id) -> {
|
||||||
@Override
|
try {
|
||||||
public void onItemClick(AdapterView<?> parentview, View view, int position, long id) {
|
parent.gotoProfileActivity(resultList.get(position).getString("id"));
|
||||||
try {
|
} catch (JSONException e) {
|
||||||
parent.gotoProfileActivity(resultList.get(position).getString("id"));
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
} catch (JSONException e) {
|
Crashlytics.logException(e);
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -85,62 +80,54 @@ public class Top10Fragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestTop10() {
|
private StringRequest getStringRequestTop10() {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_TOP10, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_TOP10, response -> {
|
||||||
|
Log.d(TAG, "Top 10 stats: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Top 10 stats: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
if (!error) {
|
||||||
|
JSONArray users = jObj.getJSONArray("msg");
|
||||||
|
resultList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
for(int i=0;i<users.length();i++){
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject user = users.getJSONObject(i);
|
||||||
boolean error = jObj.getBoolean("error");
|
resultList.add(user);
|
||||||
if (!error) {
|
|
||||||
JSONArray users = jObj.getJSONArray("msg");
|
|
||||||
resultList = new ArrayList<>();
|
|
||||||
|
|
||||||
for(int i=0;i<users.length();i++){
|
|
||||||
JSONObject user = users.getJSONObject(i);
|
|
||||||
resultList.add(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
myListAdapter = new Top10ListAdapter(
|
|
||||||
parent.getApplicationContext(),
|
|
||||||
resultList);
|
|
||||||
|
|
||||||
myListView.setAdapter(myListAdapter);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting top 10 stats (Server returned error): " + errorMsg);
|
|
||||||
parent.showMessage(getResources().getString(R.string.txt_errormsg_gettop10));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileActivity activity = (ProfileActivity) getActivity();
|
myListAdapter = new Top10ListAdapter(
|
||||||
if(activity != null){
|
parent.getApplicationContext(),
|
||||||
activity.hideDialog();
|
resultList);
|
||||||
}else{
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not get parent Activity");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
myListView.setAdapter(myListAdapter);
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
} else {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting top 10 stats (Server returned error): " + errorMsg);
|
||||||
|
parent.showMessage(getResources().getString(R.string.txt_errormsg_gettop10));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting top 10 stats: " + error.getMessage());
|
|
||||||
|
|
||||||
ProfileActivity activity = (ProfileActivity) getActivity();
|
ProfileActivity activity = (ProfileActivity) getActivity();
|
||||||
if(activity != null){
|
if(activity != null){
|
||||||
activity.hideDialog();
|
activity.hideDialog();
|
||||||
activity.handleVolleyErrorResponse();
|
|
||||||
}else{
|
}else{
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Could not get parent Activity");
|
Crashlytics.log(Log.ERROR, TAG, "Could not get parent Activity");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}, error -> {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Error getting top 10 stats: " + error.getMessage());
|
||||||
|
|
||||||
|
ProfileActivity activity = (ProfileActivity) getActivity();
|
||||||
|
if(activity != null){
|
||||||
|
activity.hideDialog();
|
||||||
|
activity.handleVolleyErrorResponse();
|
||||||
|
}else{
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Could not get parent Activity");
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -12,15 +13,12 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import io.fabric.sdk.android.Fabric;
|
|
||||||
|
|
||||||
import com.beardedhen.androidbootstrap.BootstrapButton;
|
import com.beardedhen.androidbootstrap.BootstrapButton;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.twitter.sdk.android.core.Callback;
|
import com.twitter.sdk.android.core.Callback;
|
||||||
import com.twitter.sdk.android.core.DefaultLogger;
|
import com.twitter.sdk.android.core.DefaultLogger;
|
||||||
import com.twitter.sdk.android.core.Result;
|
import com.twitter.sdk.android.core.Result;
|
||||||
import com.twitter.sdk.android.core.Twitter;
|
import com.twitter.sdk.android.core.Twitter;
|
||||||
import com.twitter.sdk.android.core.TwitterAuthToken;
|
|
||||||
import com.twitter.sdk.android.core.TwitterConfig;
|
import com.twitter.sdk.android.core.TwitterConfig;
|
||||||
import com.twitter.sdk.android.core.TwitterCore;
|
import com.twitter.sdk.android.core.TwitterCore;
|
||||||
import com.twitter.sdk.android.core.TwitterAuthConfig;
|
import com.twitter.sdk.android.core.TwitterAuthConfig;
|
||||||
@@ -66,8 +64,16 @@ public class TwitterButtonFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
mContext = getActivity().getApplicationContext();
|
try{
|
||||||
|
Activity mActivity = getActivity();
|
||||||
|
assert mActivity != null;
|
||||||
|
mContext = mActivity.getApplicationContext();
|
||||||
|
}catch(Exception e){
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Could not get activity for TwitterButton");
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
}
|
||||||
|
|
||||||
TwitterConfig config = new TwitterConfig.Builder(mContext)
|
TwitterConfig config = new TwitterConfig.Builder(mContext)
|
||||||
.logger(new DefaultLogger(Log.INFO))
|
.logger(new DefaultLogger(Log.INFO))
|
||||||
.twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET))
|
.twitterAuthConfig(new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET))
|
||||||
@@ -85,10 +91,6 @@ public class TwitterButtonFragment extends Fragment {
|
|||||||
public void success(Result<TwitterSession> result) {
|
public void success(Result<TwitterSession> result) {
|
||||||
Log.e("Debug", "onSuccess wird ausgeführt");
|
Log.e("Debug", "onSuccess wird ausgeführt");
|
||||||
session = result.data;
|
session = result.data;
|
||||||
TwitterAuthToken authToken = session.getAuthToken();
|
|
||||||
String token = authToken.token;
|
|
||||||
String secret = authToken.secret;
|
|
||||||
|
|
||||||
((LoginActivity) getActivity()).handleSocialMediaLogin((Long.toString(session.getUserId())), "twitter", session.getUserName(), "");
|
((LoginActivity) getActivity()).handleSocialMediaLogin((Long.toString(session.getUserId())), "twitter", session.getUserName(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,24 +102,14 @@ public class TwitterButtonFragment extends Fragment {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if(isAuthed()){
|
|
||||||
// log out
|
|
||||||
}else{
|
|
||||||
// log in
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpSignOut() {
|
private void setUpSignOut() {
|
||||||
btnLoginTW.setOnClickListener(new View.OnClickListener() {
|
btnLoginTW.setOnClickListener(v -> {
|
||||||
@Override
|
TwitterCore.getInstance().getSessionManager().clearActiveSession();
|
||||||
public void onClick(View v) {
|
|
||||||
TwitterCore.getInstance().getSessionManager().clearActiveSession();
|
|
||||||
|
|
||||||
Toast.makeText(mContext, "All accounts are cleared",Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, "All accounts are cleared",Toast.LENGTH_SHORT).show();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,11 +138,6 @@ public class TwitterButtonFragment extends Fragment {
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Activity activity) {
|
|
||||||
super.onAttach(activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.deke.risk.riskahead.helper;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@@ -19,11 +18,12 @@ import org.deke.risk.riskahead.R;
|
|||||||
public class AppRater {
|
public class AppRater {
|
||||||
|
|
||||||
private final static int DAYS_UNTIL_PROMPT = 1;
|
private final static int DAYS_UNTIL_PROMPT = 1;
|
||||||
|
private final static int MILLIS_UNTIL_PROMPT = DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000;
|
||||||
private final static int LAUNCHES_UNTIL_PROMPT = 10;
|
private final static int LAUNCHES_UNTIL_PROMPT = 10;
|
||||||
|
|
||||||
public static boolean app_launched(Context mContext) {
|
public static void startAppRater(Context mContext) {
|
||||||
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
|
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
|
||||||
if (prefs.getBoolean("dontshowagain", false)) { return false ; }
|
if (prefs.getBoolean("dontshowagain", false)) { return; }
|
||||||
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
|
||||||
@@ -39,16 +39,12 @@ public class AppRater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait at least n days before opening
|
// Wait at least n days before opening
|
||||||
if (launch_count >= LAUNCHES_UNTIL_PROMPT) {
|
if (launch_count >= LAUNCHES_UNTIL_PROMPT &&
|
||||||
if (System.currentTimeMillis() >= date_firstLaunch +
|
System.currentTimeMillis() >= MILLIS_UNTIL_PROMPT) {
|
||||||
(DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
|
showRateDialog(mContext, editor);
|
||||||
showRateDialog(mContext, editor);
|
}else{
|
||||||
return true;
|
editor.apply();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.apply();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
|
public static void showRateDialog(final Context mContext, final SharedPreferences.Editor editor) {
|
||||||
@@ -59,32 +55,21 @@ public class AppRater {
|
|||||||
alert.setIcon(R.drawable.logo_380);
|
alert.setIcon(R.drawable.logo_380);
|
||||||
alert.setCancelable(true);
|
alert.setCancelable(true);
|
||||||
alert.setPositiveButton(R.string.txt_rate_retenowbtn,
|
alert.setPositiveButton(R.string.txt_rate_retenowbtn,
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + AppConfig.APP_PNAME))));
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + AppConfig.APP_PNAME)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alert.setNeutralButton(R.string.txt_rate_laterbtn,
|
alert.setNeutralButton(R.string.txt_rate_laterbtn,
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> {
|
||||||
@Override
|
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
SharedPreferences.Editor editor1 = prefs.edit();
|
||||||
SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
|
|
||||||
Long date_firstLaunch = System.currentTimeMillis();
|
Long date_firstLaunch = System.currentTimeMillis();
|
||||||
editor.putLong("date_firstlaunch", date_firstLaunch);
|
editor1.putLong("date_firstlaunch", date_firstLaunch);
|
||||||
editor.apply();
|
editor1.apply();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
alert.setNegativeButton(R.string.txt_rate_neverbtn,
|
alert.setNegativeButton(R.string.txt_rate_neverbtn,
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> {
|
||||||
@Override
|
if (editor != null) {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
editor.putBoolean("dontshowagain", true);
|
||||||
if (editor != null) {
|
editor.commit();
|
||||||
editor.putBoolean("dontshowagain", true);
|
|
||||||
editor.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.deke.risk.riskahead.helper;
|
package org.deke.risk.riskahead.helper;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -7,7 +8,6 @@ import android.app.Dialog;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -37,8 +37,6 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.google.android.gms.ads.AdListener;
|
import com.google.android.gms.ads.AdListener;
|
||||||
import com.google.android.gms.ads.AdRequest;
|
import com.google.android.gms.ads.AdRequest;
|
||||||
@@ -52,7 +50,6 @@ import com.mikepenz.materialdrawer.DrawerBuilder;
|
|||||||
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
|
||||||
|
|
||||||
import org.deke.risk.riskahead.LoginActivity;
|
import org.deke.risk.riskahead.LoginActivity;
|
||||||
import org.deke.risk.riskahead.MapsActivity;
|
import org.deke.risk.riskahead.MapsActivity;
|
||||||
@@ -69,8 +66,6 @@ import java.util.HashMap;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import io.fabric.sdk.android.Fabric;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
|
* (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
|
||||||
* Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
|
* Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
|
||||||
@@ -177,7 +172,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
Log.d(TAG, "onCreate: NotificationService already running. Not starting more services.");
|
Log.d(TAG, "onCreate: NotificationService already running. Not starting more services.");
|
||||||
}
|
}
|
||||||
|
|
||||||
AppRater.app_launched(BaseActivity.this);
|
AppRater.startAppRater(BaseActivity.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
class LogoutReceiver extends BroadcastReceiver {
|
class LogoutReceiver extends BroadcastReceiver {
|
||||||
@@ -313,38 +308,35 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
item5,
|
item5,
|
||||||
new DividerDrawerItem(),
|
new DividerDrawerItem(),
|
||||||
item6,
|
item6,
|
||||||
item7).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
|
item7).withOnDrawerItemClickListener((view, position, drawerItem) -> {
|
||||||
@Override
|
|
||||||
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
|
|
||||||
|
|
||||||
switch ((int) drawerItem.getIdentifier()) {
|
switch ((int) drawerItem.getIdentifier()) {
|
||||||
case 2:
|
case 2:
|
||||||
gotoReportActivity();
|
gotoReportActivity();
|
||||||
return false;
|
return false;
|
||||||
case 3:
|
case 3:
|
||||||
gotoMapActivity();
|
gotoMapActivity();
|
||||||
return false;
|
return false;
|
||||||
case 4:
|
case 4:
|
||||||
gotoProfileActivity();
|
gotoProfileActivity();
|
||||||
return false;
|
return false;
|
||||||
case 5:
|
case 5:
|
||||||
gotoSettingsActivity();
|
gotoSettingsActivity();
|
||||||
return false;
|
return false;
|
||||||
case 6:
|
case 6:
|
||||||
gotoSubscriptionsActivity();
|
gotoSubscriptionsActivity();
|
||||||
return false;
|
return false;
|
||||||
case 7:
|
case 7:
|
||||||
logoutUser();
|
logoutUser();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e("Unknown switch page: ", Integer.toString(position));
|
Log.e("Unknown switch page: ", Integer.toString(position));
|
||||||
Crashlytics.log(Log.ERROR, TAG, "AlarmManager in BaseActivity is null. No AlarmManager found.");
|
Crashlytics.log(Log.ERROR, TAG, "AlarmManager in BaseActivity is null. No AlarmManager found.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}).build();
|
||||||
}).build();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -394,11 +386,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
.setTitle(getString(R.string.alert_internetconnection_title))
|
.setTitle(getString(R.string.alert_internetconnection_title))
|
||||||
.setMessage(getString(R.string.alert_internetconnection_text))
|
.setMessage(getString(R.string.alert_internetconnection_text))
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setNeutralButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setNeutralButton(android.R.string.yes, (dialog, which) -> logoutUser())
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
logoutUser();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
@@ -559,58 +547,53 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||||
b.setTitle(R.string.txt_language_title);
|
b.setTitle(R.string.txt_language_title);
|
||||||
String[] types = {"ar - العربية", "de - Deutsch", "en - English", "es - Español", "et - Eesti keel", "fi - Suomi", "fr - Français", "lv - Latviešu valoda", "mn - Монгол хэл", "nl - Nederlands", "pl - Polszczyzna", "pt - Português do Brasil", "ru - Pусский", "tr - Türkçe"};
|
String[] types = {"ar - العربية", "de - Deutsch", "en - English", "es - Español", "et - Eesti keel", "fi - Suomi", "fr - Français", "lv - Latviešu valoda", "mn - Монгол хэл", "nl - Nederlands", "pl - Polszczyzna", "pt - Português do Brasil", "ru - Pусский", "tr - Türkçe"};
|
||||||
b.setItems(types, new DialogInterface.OnClickListener() {
|
b.setItems(types, (dialog, which) -> {
|
||||||
|
|
||||||
@Override
|
dialog.dismiss();
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
switch (which) {
|
||||||
|
case 0:
|
||||||
dialog.dismiss();
|
setLocale("ar");
|
||||||
switch (which) {
|
break;
|
||||||
case 0:
|
case 1:
|
||||||
setLocale("ar");
|
setLocale("de");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 2:
|
||||||
setLocale("de");
|
setLocale("en");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 3:
|
||||||
setLocale("en");
|
setLocale("es");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 4:
|
||||||
setLocale("es");
|
setLocale("et");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
setLocale("et");
|
setLocale("fi");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 6:
|
||||||
setLocale("fi");
|
setLocale("fr");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 7:
|
||||||
setLocale("fr");
|
setLocale("lv");
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 8:
|
||||||
setLocale("lv");
|
setLocale("mn");
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 9:
|
||||||
setLocale("mn");
|
setLocale("nl");
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 10:
|
||||||
setLocale("nl");
|
setLocale("pl");
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 11:
|
||||||
setLocale("pl");
|
setLocale("pt");
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 12:
|
||||||
setLocale("pt");
|
setLocale("ru");
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 13:
|
||||||
setLocale("ru");
|
setLocale("tr");
|
||||||
break;
|
break;
|
||||||
case 13:
|
|
||||||
setLocale("tr");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
b.show();
|
b.show();
|
||||||
@@ -628,6 +611,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
private void showAboutInfoDialog() {
|
private void showAboutInfoDialog() {
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
View dialoglayout = inflater.inflate(R.layout.dialog_about, null);
|
View dialoglayout = inflater.inflate(R.layout.dialog_about, null);
|
||||||
@@ -644,10 +628,8 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this)
|
AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this)
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
//do nothing
|
||||||
//do nothing
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.setView(dialoglayout);
|
builder.setView(dialoglayout);
|
||||||
@@ -674,18 +656,10 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
alert.setIcon(R.drawable.logo_380);
|
alert.setIcon(R.drawable.logo_380);
|
||||||
alert.setCancelable(true);
|
alert.setCancelable(true);
|
||||||
alert.setPositiveButton(R.string.txt_feedback_sendbtn,
|
alert.setPositiveButton(R.string.txt_feedback_sendbtn,
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> sendFeedback(input.getText().toString()));
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
sendFeedback(input.getText().toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alert.setNegativeButton(R.string.txt_feedback_cancelbtn,
|
alert.setNegativeButton(R.string.txt_feedback_cancelbtn,
|
||||||
new DialogInterface.OnClickListener() {
|
(dialog, which) -> {
|
||||||
@Override
|
// do nothing
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AlertDialog ad = alert.create();
|
AlertDialog ad = alert.create();
|
||||||
@@ -711,35 +685,25 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestSendFeedback(final String feedback, final String sysprop) {
|
private StringRequest getStringRequestSendFeedback(final String feedback, final String sysprop) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_SEND_FEEDBACK, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_SEND_FEEDBACK, response -> {
|
||||||
|
Log.d(TAG, "Send Feedback: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Send Feedback: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
showMessage(getString(R.string.txt_feedback_response));
|
||||||
boolean error = jObj.getBoolean("error");
|
} else {
|
||||||
|
String errorMsg = jObj.getString("error_msg");
|
||||||
if (!error) {
|
Crashlytics.log(Log.ERROR, TAG, "Error sending feedback (server returned error): " + errorMsg);
|
||||||
showMessage(getString(R.string.txt_feedback_response));
|
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error sending feedback (server returned error): " + errorMsg);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Exception caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "Exception caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
}, error -> Crashlytics.log(Log.ERROR, TAG, "Error sending feedback: " + error.getMessage())) {
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error sending feedback: " + error.getMessage());
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
@@ -802,7 +766,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dropBreadCumb(String category, String action, String label, long value) {
|
public void dropBreadCrumb(String category, String action, String label, long value) {
|
||||||
String breadCrumb = String.format("%s|%s|%s|%s", category, action, label, value);
|
String breadCrumb = String.format("%s|%s|%s|%s", category, action, label, value);
|
||||||
Crashlytics.log(breadCrumb);
|
Crashlytics.log(breadCrumb);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ import android.support.v4.app.TaskStackBuilder;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.StringRequest;
|
import com.android.volley.toolbox.StringRequest;
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
@@ -208,37 +206,27 @@ public class NotificationService extends Service {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private StringRequest getStringRequestIncidentsFromAreaAndTime(final Double latitude, final Double longitude, final int radius, final String time) {
|
private StringRequest getStringRequestIncidentsFromAreaAndTime(final Double latitude, final Double longitude, final int radius, final String time) {
|
||||||
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMAREATIME, new Response.Listener<String>() {
|
return new StringRequest(Request.Method.POST, AppConfig.REST_GET_INCIDENTS_FROMAREATIME, response -> {
|
||||||
|
Log.d(TAG, "Incident notifications: " + response);
|
||||||
|
|
||||||
@Override
|
try {
|
||||||
public void onResponse(String response) {
|
JSONObject jObj = new JSONObject(response);
|
||||||
Log.d(TAG, "Incident notifications: " + response);
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
try {
|
if (!error) {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONArray notification = jObj.getJSONArray("msg");
|
||||||
boolean error = jObj.getBoolean("error");
|
sentNotification(notification);
|
||||||
|
} else {
|
||||||
if (!error) {
|
String errorMsg = jObj.getString("error_msg");
|
||||||
JSONArray notification = jObj.getJSONArray("msg");
|
int loglevel = (errorMsg.contains("No incidents found in given area and from time")) ? Log.INFO : Log.ERROR;
|
||||||
sentNotification(notification);
|
Crashlytics.log(loglevel, TAG, "Error getting incident notification (server returned error): " + errorMsg);
|
||||||
} else {
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
|
||||||
int loglevel = (errorMsg.contains("No incidents found in given area and from time")) ? Log.INFO : Log.ERROR;
|
|
||||||
Crashlytics.log(loglevel, TAG, "Error getting incident notification (server returned error): " + errorMsg);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
|
||||||
Crashlytics.logException(e);
|
|
||||||
}
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Crashlytics.log(Log.ERROR, TAG, "JSONException caught");
|
||||||
|
Crashlytics.logException(e);
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
}, error -> Crashlytics.log(Log.ERROR, TAG, "Error getting incident notification: " + error.getMessage())) {
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Crashlytics.log(Log.ERROR, TAG, "Error getting incident notification: " + error.getMessage());
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.content.UriMatcher;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
@@ -184,17 +185,17 @@ public class PlaceProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(@NonNull Uri uri) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri uri, ContentValues values) {
|
public Uri insert(@NonNull Uri uri, ContentValues values) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +205,7 @@ public class PlaceProvider extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String selection,String[] selectionArgs) {
|
public int update(@NonNull Uri uri, ContentValues values, String selection,String[] selectionArgs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,15 +228,15 @@ public class PlaceProvider extends ContentProvider {
|
|||||||
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
|
BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
String line = "";
|
String line;
|
||||||
while( ( line = br.readLine()) != null){
|
while( ( line = br.readLine()) != null){
|
||||||
sb.append(line);
|
sb.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = sb.toString();
|
data = sb.toString();
|
||||||
System.out.println("DATA:"+data);
|
Log.d(TAG,"DATA:"+data);
|
||||||
br.close();
|
br.close();
|
||||||
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
@@ -264,7 +265,7 @@ public class PlaceProvider extends ContentProvider {
|
|||||||
|
|
||||||
// Building the url to the web service
|
// Building the url to the web service
|
||||||
String url = "https://maps.googleapis.com/maps/api/place/details/"+output+"?"+parameters;
|
String url = "https://maps.googleapis.com/maps/api/place/details/"+output+"?"+parameters;
|
||||||
System.out.println("URL: "+url);
|
Log.d(TAG,"URL: "+url);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,7 +291,7 @@ public class PlaceProvider extends ContentProvider {
|
|||||||
// Building the url to the web service
|
// Building the url to the web service
|
||||||
String url = "https://maps.googleapis.com/maps/api/place/autocomplete/"+output+"?"+parameters;
|
String url = "https://maps.googleapis.com/maps/api/place/autocomplete/"+output+"?"+parameters;
|
||||||
|
|
||||||
System.out.println("URL: "+url);
|
Log.d(TAG,"URL: "+url);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
|
android:baselineAligned="false"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|||||||
Reference in New Issue
Block a user