DT @30.10.2015: SQLite durch sharedPreferences getauscht. ViewReport erweitert. Design changes.

This commit is contained in:
Dennis Thießen
2015-10-30 13:53:27 +01:00
parent a7fbf78dd4
commit 7a41b99ccd
23 changed files with 875 additions and 111 deletions

View File

@@ -45,5 +45,5 @@ dependencies {
compile('com.twitter.sdk.android:twitter-core:1.4.1@aar') {
transitive = true;
}
compile 'com.beardedhen:androidbootstrap:2.0.0'
}

View File

@@ -45,30 +45,33 @@
android:label="@string/title_activity_start" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:configChanges="orientation"
android:label="@string/app_name"
android:parentActivityName=".StartActivity" >
>
</activity>
<activity android:name="com.twitter.sdk.android.core.identity.OAuthActivity" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
</activity>
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="@string/title_activity_entrance"
android:parentActivityName=".LoginActivity" >
</activity>
<activity
android:name=".MapsActivity"
android:configChanges="orientation"
@@ -77,12 +80,10 @@
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!-- Points to searchable activity -->
<meta-data
android:name="android.app.default_searchable"
android:value=".MapsActivity" />
<!-- Points to searchable meta data -->
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
@@ -99,21 +100,35 @@
android:label="@string/title_activity_user_config"
android:parentActivityName=".MainActivity" >
</activity>
<activity
android:name=".ReportActivity"
android:configChanges="orientation"
android:label="@string/title_activity_report" >
</activity>
<activity
android:name=".SettingsActivity"
android:configChanges="orientation"
android:label="@string/title_activity_settings" >
</activity>
<activity
android:name=".SubscriptionsActivity"
android:configChanges="orientation"
android:label="@string/title_activity_subscriptions" >
</activity>
</application>
<activity
android:name=".ReportlistActivity"
android:configChanges="orientation"
android:label="@string/title_activity_reportlist" >
</activity>
<activity
android:name=".ViewReportActivity"
android:configChanges="orientation"
android:label="@string/title_activity_view_report" >
</activity>
</application>
</manifest>

View File

@@ -22,7 +22,6 @@ import org.deke.risk.riskahead.fragments.GooglePlusButtonFragment;
import org.deke.risk.riskahead.fragments.TwitterButtonFragment;
import org.deke.risk.riskahead.helper.AppConfig;
import org.deke.risk.riskahead.helper.AppController;
import org.deke.risk.riskahead.helper.SQLiteHandler;
import org.deke.risk.riskahead.helper.SessionManager;
import org.json.JSONException;
import org.json.JSONObject;
@@ -39,6 +38,7 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
private final static String TAG = LoginActivity.class.getSimpleName();
private final static String EXTRA_MESSAGE = "org.deke.risk.riskahead.MESSAGE";
private final static String mActivityTitle = "RiskAhead";
private String msg_intent;
private Button btn_login;
@@ -47,7 +47,6 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
private TextView input_password;
private ProgressDialog pDialog;
private SQLiteHandler db;
private SessionManager session;
@@ -61,7 +60,6 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
db = new SQLiteHandler(getApplicationContext());
session = new SessionManager(getApplicationContext());
if(msg_intent.equals("login")){
@@ -161,7 +159,7 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
}
String tag_string_req = "sociallogin";
db.deleteUsers();
session.removeUser();
showDialog();
StringRequest strReq = getStringRequestSocialMediaLogin(key, providerType, username, email);
@@ -239,8 +237,8 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
String token = user.getString("token");
// Inserting row in users table
db.addUser(uid, username, name, surname, email, status, providerType, created_at, updated_at, token);
db.close();
session.addUser(uid, username, name, surname, email, status, providerType, created_at, updated_at, token);
// Launch login activity
Intent intent = new Intent(
LoginActivity.this,
@@ -338,7 +336,7 @@ public class LoginActivity extends AppCompatActivity implements FacebookButtonFr
.show();
}else {
// Inserting row in users table
db.addUser(uid, username, name, surname, email, status, providerType, created_at, updated_at, token);
session.addUser(uid, username, name, surname, email, status, providerType, created_at, updated_at, token);
// user successfully logged in
// Create login session

View File

@@ -40,6 +40,7 @@ public class MainActivity extends BaseActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
Intent intent = getIntent();
msg_input = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

View File

@@ -43,25 +43,29 @@ import java.util.HashMap;
import java.util.Map;
public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<Cursor> {
public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<Cursor>, GoogleMap.OnInfoWindowClickListener {
private final static String mActivityTitle = "Risk Map";
private static final String TAG = MapsActivity.class.getSimpleName();
private static GoogleMap mMap;
Marker mMarker;
HashMap<String, String> markerIDs = new HashMap<String, String>();
private LatLng myLocation;
private LatLng markedLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.frag_maps_map)).getMap();
mMap.getUiSettings().setZoomControlsEnabled(true);
handleIntent(getIntent());
findViewById(R.id.btn_maps_confirm_position).setVisibility(View.GONE);
mMap.setOnInfoWindowClickListener(this);
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
@@ -130,7 +134,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
position = new LatLng(Double.parseDouble(c.getString(1)),Double.parseDouble(c.getString(2)));
markerOptions.position(position);
markerOptions.title(c.getString(0));
mMap.addMarker(markerOptions);
mMarker = mMap.addMarker(markerOptions);
}
if(position!=null){
CameraUpdate cameraPosition = CameraUpdateFactory.newLatLng(position);
@@ -140,7 +144,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
if (position != null) {
myLocation = new LatLng(position.latitude,position.longitude);
}
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 20));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLocation, 12.0f));
}
@Override
@@ -226,7 +230,8 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
JSONObject incident = incidents.getJSONObject(i);
LatLng pos = new LatLng(Double.parseDouble(incident.getString("latitude")),Double.parseDouble(incident.getString("longitude")));
Log.d(TAG, "Adding marker with position: " + pos.latitude +" : "+ pos.longitude);
mMap.addMarker(new MarkerOptions().position(pos).title(incident.getString("text_short")).snippet("Test" + i));
mMarker = mMap.addMarker(new MarkerOptions().position(pos).title(incident.getString("text_short")).snippet("Crime Category:" + incident.getString("fid_category")));
markerIDs.put(mMarker.getId(),incident.getString("uid"));
CircleOptions circleOptions = new CircleOptions()
.center(pos)
@@ -276,4 +281,8 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
}
@Override
public void onInfoWindowClick(Marker marker) {
gotoViewReportActivity(markerIDs.get(marker.getId()));
}
}

View File

@@ -6,6 +6,7 @@ import android.provider.ContactsContract;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
@@ -28,7 +29,7 @@ import java.util.Map;
public class ProfileActivity extends BaseActivity {
private final static String mActivityTitle = "User Profile";
private final static String mActivityTitle = "User Statistics";
private final static String TAG = ProfileActivity.class.getSimpleName();
private TextView txtMemberSince;
@@ -36,6 +37,7 @@ public class ProfileActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
txtMemberSince = (TextView) findViewById(R.id.txt_profile_membersince);
txtMemberSince.setText(user.get("created_at"));
@@ -48,6 +50,12 @@ public class ProfileActivity extends BaseActivity {
String tag_string_req2 = "req_top10";
AppController.getInstance().addToRequestQueue(strReq2, tag_string_req2);
findViewById(R.id.btn_profile_viewposts).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoReportlistActivity();
}
});
}
@Override

View File

@@ -66,6 +66,7 @@ public class ReportActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
Spinner spinner = (Spinner) findViewById(R.id.dd_report_category);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.incident_categories, android.R.layout.simple_spinner_item);
@@ -89,11 +90,10 @@ public class ReportActivity extends BaseActivity {
restoreSharedPreferences();
if(txtDay.getText().toString() == "") {
txtDay.setText(new StringBuilder()
.append(day).append("-").append(month + 1).append("-")
.append(year).append(" "));
.append(year).append("-").append(month + 1).append("-")
.append(day).append(" "));
}
if(txtTime.getText().toString() == "") {
@@ -264,8 +264,8 @@ public class ReportActivity extends BaseActivity {
month = selectedMonth;
day = selectedDay;
txtDay.setText(new StringBuilder().append(day)
.append("-").append(month + 1).append("-").append(year)
txtDay.setText(new StringBuilder().append(year)
.append("-").append(month + 1).append("-").append(day)
.append(" "));
}
};

View File

@@ -0,0 +1,142 @@
package org.deke.risk.riskahead;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import org.deke.risk.riskahead.helper.AppConfig;
import org.deke.risk.riskahead.helper.AppController;
import org.deke.risk.riskahead.helper.BaseActivity;
import org.deke.risk.riskahead.helper.ReportListAdapter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ReportlistActivity extends BaseActivity {
private final static String mActivityTitle = "Reports";
private final static String TAG = ReportlistActivity.class.getSimpleName();
ListView myListView;
ListAdapter myListAdapter;
List<JSONObject> resultList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
myListView = (ListView)findViewById(R.id.lv_reportlist_list);
//setContentView(R.layout.activity_reportlist);
String tag_string_req = "getincidentswithpositionfromid";
StringRequest strReq = getStringRequestGetIncidentsWithPositionFromUserID();
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
try {
gotoViewReportActivity(resultList.get(position).getString("uid"));
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
protected int getLayoutResourceId() {
return R.layout.activity_reportlist;
}
@Override
protected String getActivityName() {
return mActivityTitle;
}
private StringRequest getStringRequestGetIncidentsWithPositionFromUserID() {
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Map positions response with ID: " + response);
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
JSONArray incidents = jObj.getJSONArray("message");
resultList = new ArrayList<JSONObject>();
for(int i=0;i<incidents.length();i++){
JSONObject incident = incidents.getJSONObject(i);
resultList.add(incident);
}
myListAdapter = new ReportListAdapter(
getApplicationContext(),
resultList);
myListView.setAdapter(myListAdapter);
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Report Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("tag", "getincidentsfromuserid");
params.put("uid", user.get("uid"));
params.put("token", user.get("token"));
return params;
}
};
}
}

View File

@@ -36,6 +36,7 @@ public class SettingsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
txtUsername = (TextView) findViewById(R.id.txt_settings_username);
txtName = (TextView) findViewById(R.id.txt_settings_name);
@@ -123,7 +124,7 @@ public class SettingsActivity extends BaseActivity {
if (!error) {
showMessage(jObj.getString("msg"));
JSONObject user = jObj.getJSONObject("user");
db.updateUser(jObj.getString("uid"),user.getString("username"),user.getString("name"),user.getString("surname"),user.getString("email"),user.getString("status"),null,user.getString("created_at"),user.getString("updated_at"),user.getString("token"));
session.addUser(jObj.getString("uid"), user.getString("username"), user.getString("name"), user.getString("surname"), user.getString("email"), user.getString("status"), null, user.getString("created_at"), user.getString("updated_at"), user.getString("token"));
finish();
startActivity(getIntent());
} else {

View File

@@ -13,6 +13,7 @@ public class SubscriptionsActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
}
@Override

View File

@@ -0,0 +1,163 @@
package org.deke.risk.riskahead;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import org.deke.risk.riskahead.helper.AppConfig;
import org.deke.risk.riskahead.helper.AppController;
import org.deke.risk.riskahead.helper.BaseActivity;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class ViewReportActivity extends BaseActivity {
private final static String mActivityTitle = "ViewReport";
private final static String TAG = ViewReportActivity.class.getSimpleName();
private EditText txtTitle;
private EditText txtDescription;
private Spinner txtCrimeCategory;
private EditText txtPosition;
private EditText txtDate;
private EditText txtTime;
private TextView txtPositionDetail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
txtTitle = (EditText) findViewById(R.id.input_viewreport_short);
txtDescription = (EditText) findViewById(R.id.input_viewreport_long);
txtCrimeCategory = (Spinner) findViewById(R.id.dd_viewreport_category);
txtDate = (EditText) findViewById(R.id.input_viewreport_date);
txtTime = (EditText) findViewById(R.id.input_viewreport_time);
txtPosition = (EditText) findViewById(R.id.input_viewreport_position);
txtPositionDetail = (TextView) findViewById(R.id.lbl_viewreport_position_detail);
Spinner spinner = (Spinner) findViewById(R.id.dd_viewreport_category);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.incident_categories, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Intent intent = getIntent();
String uid = intent.getStringExtra(BaseActivity.EXTRA_MESSAGE);
String tag_string_req = "getincidentwithpositionfromid";
StringRequest strReq = getStringRequestGetIncidentWithPositionFromID(uid);
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
findViewById(R.id.btn_viewreport_upvote).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMessage("Upvote!");
}
});
findViewById(R.id.btn_viewreport_downvote).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMessage("Downvote!");
}
});
}
@Override
protected int getLayoutResourceId() {
return R.layout.activity_view_report;
}
@Override
protected String getActivityName() {
return mActivityTitle;
}
private StringRequest getStringRequestGetIncidentWithPositionFromID(final String incidentid) {
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Incident with ID response: " + response);
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
JSONObject incident = jObj.getJSONArray("message").getJSONObject(0);
txtTitle.setText(incident.getString("text_short"));
txtDescription.setText(incident.getString("text_long"));
txtCrimeCategory.setSelection(incident.getInt("fid_category"));
String[] happened_at = incident.getString("happened_at").split(" ");
txtDate.setText(happened_at[0]);
txtTime.setText(happened_at[1].substring(0,5));
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(incident.getDouble("latitude"), incident.getDouble("longitude"), 1);
txtPosition.setText(addresses.get(0).getLocality());
txtPositionDetail.setText(addresses.get(0).getAddressLine(0));
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Report Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("tag", "getincidentfromid");
params.put("uid", user.get("uid"));
params.put("token", user.get("token"));
params.put("incidentid", incidentid);
return params;
}
};
}
}

View File

@@ -29,8 +29,10 @@ import org.deke.risk.riskahead.MapsActivity;
import org.deke.risk.riskahead.R;
import org.deke.risk.riskahead.ReportActivity;
import org.deke.risk.riskahead.ProfileActivity;
import org.deke.risk.riskahead.ReportlistActivity;
import org.deke.risk.riskahead.SettingsActivity;
import org.deke.risk.riskahead.SubscriptionsActivity;
import org.deke.risk.riskahead.ViewReportActivity;
import java.util.HashMap;
@@ -45,31 +47,27 @@ public abstract class BaseActivity extends AppCompatActivity {
private ArrayAdapter<String> mAdapter;
private ShareActionProvider mShareActionProvider;
public SQLiteHandler db;
public SessionManager session;
public HashMap<String, String> user;
public ProgressDialog pDialog;
public void userHasToBeLoggedIn(){
if (!session.isLoggedIn()) {
logout();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResourceId());
// SqLite database handler
db = new SQLiteHandler(getApplicationContext());
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
// session manager
session = new SessionManager(getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
user = db.getUserDetails();
user = session.getUserDetails();
mDrawerList = (ListView)findViewById(R.id.navList);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
@@ -82,8 +80,12 @@ public abstract class BaseActivity extends AppCompatActivity {
}
public void logoutUser() {
session.removeUser();
logout();
}
public void logout() {
session.setLogin(false);
db.deleteUsers();
// Launching the login activity
Intent intent = new Intent(this, LoginActivity.class);
@@ -136,7 +138,7 @@ public abstract class BaseActivity extends AppCompatActivity {
}
private void addDrawerItems() {
String[] osArray = { "Start", "Report", "Incident Map", "User Profile", "Account Settings", "Subscriptions", "Logout" };
String[] osArray = { "Start", "Report", "Incident Map", "User Statistics", "Account Settings", "Subscriptions", "Logout" };
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
@@ -193,6 +195,12 @@ public abstract class BaseActivity extends AppCompatActivity {
startActivity(intent);
}
public void gotoReportlistActivity(){
Intent intent;
intent = new Intent(getApplicationContext(), ReportlistActivity.class);
startActivity(intent);
}
public void gotoReportActivity(String position){
Intent intent;
intent = new Intent(getApplicationContext(), ReportActivity.class);
@@ -224,6 +232,13 @@ public abstract class BaseActivity extends AppCompatActivity {
startActivity(intent);
}
public void gotoViewReportActivity(String uid){
Intent intent;
intent = new Intent(getApplicationContext(), ViewReportActivity.class);
intent.putExtra(EXTRA_MESSAGE, uid);
startActivity(intent);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);

View File

@@ -67,7 +67,7 @@ public class SQLiteHandler extends SQLiteOpenHelper {
/**
* Storing user details in database
* */
* *//*
public void addUser(String uid, String username, String name, String surname, String email, String status, String provider_type, String created_at, String updated_at, String token) {
SQLiteDatabase db = this.getWritableDatabase();
@@ -95,9 +95,9 @@ public class SQLiteHandler extends SQLiteOpenHelper {
addUser(uid,username,name,surname,email,status,provider_type,created_at,updated_at,token);
}
/**
*//**
* Getting user data from database
* */
* *//*
public HashMap<String, String> getUserDetails() {
HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "SELECT * FROM " + TABLE_LOGIN;
@@ -126,9 +126,9 @@ public class SQLiteHandler extends SQLiteOpenHelper {
return user;
}
/**
*//**
* Getting user login status return true if rows are there in table
* */
* *//*
public int getRowCount() {
String countQuery = "SELECT * FROM " + TABLE_LOGIN;
SQLiteDatabase db = this.getReadableDatabase();
@@ -141,9 +141,9 @@ public class SQLiteHandler extends SQLiteOpenHelper {
return rowCount;
}
/**
*//**
* Re crate database Delete all tables and create them again
* */
* *//*
public void deleteUsers() {
SQLiteDatabase db = this.getWritableDatabase();
// Delete All Rows
@@ -152,5 +152,7 @@ public class SQLiteHandler extends SQLiteOpenHelper {
Log.d(TAG, "Deleted all user info from sqlite");
}
*/
}

View File

@@ -5,33 +5,96 @@ import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import java.util.HashMap;
public class SessionManager {
private static String TAG = SessionManager.class.getSimpleName();
SharedPreferences pref;
SharedPreferences status;
public SharedPreferences userdata;
Editor editor;
Editor statusEditor;
Editor userDataEditor;
Context _context;
int PRIVATE_MODE = 0;
private static final String PREF_NAME = "AndroidHiveLogin";
private static final String PREF_NAME = "AndroidLogin";
private static final String USERDATA_NAME = "AndroidLoginUser";
private static final String KEY_UID = "uid";
private static final String KEY_USERNAME = "username";
private static final String KEY_NAME = "name";
private static final String KEY_SURNAME = "surname";
private static final String KEY_EMAIL = "email";
private static final String KEY_STATUS = "status";
private static final String PROVIDER_TYPE = "providerType";
private static final String KEY_CREATED_AT = "created_at";
private static final String KEY_UPDATED_AT = "updated_at";
private static final String TOKEN = "token";
private static final String KEY_IS_LOGGEDIN = "isLoggedIn";
public SessionManager(Context context) {
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
status = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
userdata = _context.getSharedPreferences(USERDATA_NAME, PRIVATE_MODE);
statusEditor = status.edit();
userDataEditor = userdata.edit();
}
public void setLogin(boolean isLoggedIn) {
editor.putBoolean(KEY_IS_LOGGEDIN, isLoggedIn);
editor.commit();
Log.d(TAG, "User login session modified!");
statusEditor.putBoolean(KEY_IS_LOGGEDIN, isLoggedIn);
statusEditor.apply();
}
public boolean isLoggedIn(){
return pref.getBoolean(KEY_IS_LOGGEDIN, false);
return status.getBoolean(KEY_IS_LOGGEDIN, false);
}
public void addUser(String uid, String username, String name, String surname, String email, String status, String provider_type, String created_at, String updated_at, String token) {
userDataEditor.putString(KEY_UID, uid); //UID
userDataEditor.putString(KEY_USERNAME, username); // Username
userDataEditor.putString(KEY_NAME, name); // Name
userDataEditor.putString(KEY_SURNAME, surname); // Surame
userDataEditor.putString(KEY_EMAIL, email); // Email
userDataEditor.putString(KEY_STATUS, status); // Status
userDataEditor.putString(PROVIDER_TYPE, provider_type); // ProviderType
userDataEditor.putString(KEY_CREATED_AT, created_at); // Created At
userDataEditor.putString(KEY_UPDATED_AT, updated_at); // Updated At
userDataEditor.putString(TOKEN, token); // TOKEN
userDataEditor.apply();
Log.d(TAG, "New user written to sharedPreferences: " + uid);
}
/**
* Getting user data from database
* */
public HashMap<String, String> getUserDetails() {
HashMap<String, String> user = new HashMap<String, String>();
user.put(KEY_UID, userdata.getString(KEY_UID, null));
user.put(KEY_USERNAME, userdata.getString(KEY_USERNAME, null));
user.put(KEY_NAME, userdata.getString(KEY_NAME, null));
user.put(KEY_SURNAME, userdata.getString(KEY_SURNAME, null));
user.put(KEY_EMAIL, userdata.getString(KEY_EMAIL, null));
user.put(KEY_STATUS, userdata.getString(KEY_STATUS, null));
user.put(PROVIDER_TYPE, userdata.getString(PROVIDER_TYPE, null));
user.put(KEY_CREATED_AT, userdata.getString(KEY_CREATED_AT, null));
user.put(KEY_UPDATED_AT, userdata.getString(KEY_UPDATED_AT, null));
user.put(TOKEN, userdata.getString(TOKEN, null));
Log.d(TAG, "Fetching user from sharedPrefs: " + user.toString());
return user;
}
public void removeUser(){
userdata.edit().clear().apply();
}
}

View File

@@ -1,5 +1,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/bg_login"

View File

@@ -29,7 +29,7 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="52dp"
android:textColor="#8a999999"/>
android:textColor="#aa999999"/>
<TextView
android:id="@+id/txt_main_incidents"
@@ -47,7 +47,7 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_marginTop="34dp"
android:textColor="#8a999999"
android:textColor="#aa999999"
android:layout_centerHorizontal="true" />
</LinearLayout>
@@ -57,7 +57,7 @@
<LinearLayout
android:id="@+id/ll_01"
android:gravity="center"
android:background="@color/white"
android:background="#33FF0000"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"

View File

@@ -8,13 +8,21 @@
android:background="#8ae6e6e6"
tools:context="org.deke.risk.riskahead.ProfileActivity">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rl_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_margin="10dp"
android:layout_marginBottom="20dp"
android:padding="4dp"
android:background="#11222222"
android:orientation="vertical" >
<TextView
@@ -31,6 +39,7 @@
android:layout_below="@+id/lbl_profile_stats"
android:stretchColumns="1"
android:id="@+id/tableLayout">
<TableRow>
<TextView
android:id="@+id/lbl_profile_membersince"
@@ -106,21 +115,22 @@
</TableRow>
</TableLayout>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_profile_viewposts"
bootstrap:bootstrapText="@string/btn_profile_viewposts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapBrand="primary"
bootstrap:roundedCorners="true"
android:layout_column="0"
android:layout_below="@+id/tableLayout"
android:layout_marginTop="31dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_main_content_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:layout_marginBottom="20dp"
android:padding="4dp"
android:background="#11222222"
android:orientation="vertical" >
<TextView
android:id="@+id/lbl_profile_top10"
android:text="@string/lbl_profile_top10"
android:layout_below="@+id/btn_profile_viewposts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
@@ -163,9 +173,31 @@
</TableRow>
</TableLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_01"
android:gravity="center"
android:background="#33FF0000"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp">
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_profile_viewposts"
bootstrap:bootstrapText="@string/btn_profile_viewposts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapBrand="primary"
bootstrap:roundedCorners="true" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/navList"
android:layout_width="200dp"

View File

@@ -2,6 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bootstrap="http://schemas.android.com/apk/res-auto"
xmlns:fontawesometext="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:background="#8ae6e6e6"
android:layout_width="match_parent"
@@ -18,7 +19,7 @@
android:id="@+id/rl_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:padding="15dp"
android:layout_weight="1"
android:orientation="vertical">
@@ -161,16 +162,13 @@
android:layout_alignParentStart="true" />
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_01"
android:gravity="center"
android:background="@color/white"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp">
<LinearLayout
android:id="@+id/ll_01"
android:gravity="center"
android:background="@color/white"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_marginBottom="0dp">
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_report_report"

View File

@@ -0,0 +1,33 @@
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bootstrap="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:background="#8ae6e6e6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ReportlistActivity">
<RelativeLayout
android:id="@+id/rl_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:orientation="vertical" >
<ListView
android:id="@+id/lv_reportlist_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<ListView
android:id="@+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffeeee"/>
</android.support.v4.widget.DrawerLayout>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#a6000000"
android:id="@+id/txt_reportlist_lvrow_title"
android:text="Header"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#b9000000"
android:text="Long Text"
android:id="@+id/txt_reportlist_lvrow_text"/>
</LinearLayout>

View File

@@ -20,8 +20,10 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_margin="10dp"
android:layout_marginBottom="20dp"
android:padding="4dp"
android:background="#11222222"
android:orientation="vertical" >
<TextView
@@ -95,34 +97,43 @@
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_main_content_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:layout_marginBottom="20dp"
android:padding="4dp"
android:background="#11222222"
android:orientation="vertical" >
<TextView
android:id="@+id/lbl_settings_password"
android:text="@string/lbl_settings_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/txt_settings_email"/>
android:layout_marginTop="10dp"/>
<EditText
android:id="@+id/txt_settings_password"
android:inputType="textPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="7"
android:layout_below="@+id/lbl_settings_password"/>
<EditText
android:id="@+id/txt_settings_password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lbl_settings_password"/>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_settings_req_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapText="@string/btn_settings_req_password"
bootstrap:bootstrapBrand="primary"
bootstrap:roundedCorners="true"
android:layout_alignTop="@+id/lbl_settings_password"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_settings_req_password"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapText="@string/btn_settings_req_password"
bootstrap:bootstrapBrand="primary"
bootstrap:roundedCorners="true"
android:layout_below="@+id/txt_settings_password" />
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_01"

View File

@@ -0,0 +1,243 @@
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bootstrap="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:background="#8ae6e6e6"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewReportActivity">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/rl_main_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/lbl_viewreport_short"
android:text="@string/lbl_report_short"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/input_viewreport_short"
android:layout_alignStart="@+id/input_viewreport_short"/>
<EditText
android:id="@+id/input_viewreport_short"
android:hint="@string/input_report_short_hint"
android:inputType="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/input_login"
android:textColorHint="@color/input_login_hint"
android:enabled="false"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/lbl_viewreport_long"
android:text="@string/lbl_report_long"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/input_viewreport_short" />
<EditText
android:id="@+id/input_viewreport_long"
android:hint="@string/input_report_long_hint"
android:inputType="textMultiLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|left"
android:padding="10dp"
android:singleLine="true"
android:textColor="@color/input_login"
android:textColorHint="@color/input_login_hint"
android:layout_below="@+id/lbl_viewreport_long"
android:scrollbars="vertical"
android:enabled="false"
android:minLines="3"/>
<TextView
android:id="@+id/lbl_viewreport_category"
android:text="@string/lbl_report_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/input_viewreport_long" />
<Spinner
android:id="@+id/dd_viewreport_category"
android:enabled="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/lbl_viewreport_category"/>
<TextView
android:id="@+id/lbl_viewreport_date"
android:text="@string/lbl_report_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/dd_viewreport_category" />
<TextView
android:id="@+id/lbl_viewreport_time"
android:text="@string/lbl_report_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_above="@+id/input_viewreport_time"
android:layout_alignLeft="@+id/input_viewreport_time"
android:layout_alignStart="@+id/input_viewreport_time"/>
<EditText
android:id="@+id/input_viewreport_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:enabled="false"
android:ems="10"
android:layout_below="@+id/lbl_viewreport_date"
android:layout_alignLeft="@+id/lbl_viewreport_date"
android:layout_alignStart="@+id/lbl_viewreport_date"
android:focusable="false"/>
<EditText
android:id="@+id/input_viewreport_time"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_alignBottom="@+id/input_viewreport_date"
android:layout_toRightOf="@+id/input_viewreport_date"
android:layout_toEndOf="@+id/input_viewreport_date"
android:focusable="false"/>
<TextView
android:id="@+id/lbl_viewreport_position"
android:text="@string/lbl_report_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_below="@+id/input_viewreport_date"
android:layout_alignLeft="@+id/input_viewreport_date"
android:layout_alignStart="@+id/input_viewreport_time"/>
<EditText
android:id="@+id/input_viewreport_position"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_below="@+id/lbl_viewreport_position"
android:layout_alignLeft="@+id/lbl_viewreport_position"
android:layout_alignStart="@+id/lbl_viewreport_position"
android:editable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/lbl_viewreport_position_detail"
android:layout_below="@+id/input_viewreport_position"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical"
android:gravity="center"
android:background="#8a999999">
<com.beardedhen.androidbootstrap.AwesomeTextView
android:id="@+id/btn_viewreport_upvote"
android:textSize="80dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapBrand="success"
bootstrap:fontAwesomeIcon="fa_angle_up"
/>
<com.beardedhen.androidbootstrap.BootstrapLabel
android:id="@+id/txt_viewreport_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_viewreport_upvote"
android:layout_centerInParent="true"
bootstrap:bootstrapBrand="primary"
bootstrap:bootstrapHeading="h4"
bootstrap:roundedCorners="true"
android:text="0"
/>
<com.beardedhen.androidbootstrap.AwesomeTextView
android:id="@+id/btn_viewreport_downvote"
android:textSize="80dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapBrand="danger"
android:layout_below="@+id/txt_viewreport_points"
bootstrap:fontAwesomeIcon="fa_angle_down"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_01"
android:gravity="center"
android:background="@color/white"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="0dp">
<Button
android:text="Edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:text="Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/navList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffeeee"/>
</android.support.v4.widget.DrawerLayout>

View File

@@ -24,7 +24,7 @@
<string name="title_activity_entrance">Risk Ahead</string>
<string name="btn_profile_logout">Logout</string>
<string name="btn_settings_change">{fa_paint_brush} Confirm changes</string>
<string name="btn_settings_change">{fa_pencil} Confirm changes</string>
<string name="lbl_profile_title">Welcome</string>
<string name="drawer_open">Open navigation drawer</string>
@@ -63,8 +63,8 @@
<string name="lbl_report_short">Title</string>
<string name="lbl_report_long">Description</string>
<string name="lbl_report_category">Crime Category</string>
<string name="lbl_report_time">Time (hh:mm)</string>
<string name="lbl_report_date">Date (dd-mm-yyyy) of incident</string>
<string name="lbl_report_time">Time </string>
<string name="lbl_report_date">Date (yyyy-mm-dd)</string>
<string name="lbl_settings_name">Name</string>
<string name="lbl_settings_surname">Surname</string>
@@ -80,7 +80,7 @@
<string name="lbl_profile_top10">Top10</string>
<string name="lbl_settings_password">Confirm Password</string>
<string name="btn_settings_req_password">{fa_paint_brush} Change password</string>
<string name="btn_settings_req_password">{fa_envelope} Request new password</string>
<string name="lbl_settings_retype_password">Retype Password</string>
<string name="menu_action_about">About</string>
@@ -95,6 +95,11 @@
<item>Personal</item>
<item>Property</item>
<item>Political</item>
</string-array>
</string-array>
<string name="title_activity_reportlist">Report List</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="title_activity_view_report">View Report</string>
</resources>