Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/brigadinhos/LocMess
Browse files Browse the repository at this point in the history
  • Loading branch information
brigadinhos committed May 18, 2017
2 parents 9b70e86 + 8689050 commit 2c7f1fe
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 159 deletions.
8 changes: 4 additions & 4 deletions LocMessClient/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
android:name=".LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>

Expand All @@ -44,11 +48,7 @@
android:label="@string/title_activity_main"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AddMessage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void onClick(View v){
addGPS();
}

FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getApplicationContext());
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getApplicationContext());
dbHelper.insertLocation(mLocation.getName(),mLocation.getSsid(),mLocation.getBle(),mLocation.getLatitude(),mLocation.getLongitude(),mLocation.getRadius(),"false");

finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void onClick(View v) {
@Override
public void onClick(View view) {
if(!keyValueMap.isEmpty()){
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(activity);
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(activity);
dbHelper.insertAllProfiles(keyValueMap);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getActivity());
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getActivity());
dbHelper.deleteLocation(locationName);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Fragment;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -44,7 +42,7 @@ public class ListMessages extends Fragment {
private ListView mMessageListView;
private List<Message> mMessageList;
private ArrayAdapter<Message> arrayAdapter;

private Handler handler;
private List<String> messageContentList;


Expand Down Expand Up @@ -74,6 +72,8 @@ public void onCreate(Bundle savedInstanceState) {

getActivity().setTitle(R.string.fragment_list_messages_title);

handler = new Handler();
handler.postDelayed(new GetMessageFromDBThread(),500);


FloatingActionButton fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
Expand Down Expand Up @@ -102,7 +102,7 @@ private void checkInternetConnection(){

dataHolder.setCentralizedMode(isConnected);

Toast.makeText(getActivity(), "has internet connection = " + isConnected, Toast.LENGTH_LONG).show();
// Toast.makeText(getActivity(), "has internet connection = " + isConnected, Toast.LENGTH_LONG).show();
}

private void fillDatabase(Activity activity) {
Expand All @@ -114,7 +114,7 @@ private void fillDatabase(Activity activity) {
}

private void createDatabase(Context context, boolean deleteDatabase){
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(context);
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(context);
if (doesDatabaseExist(context, dbHelper.getDatabaseName()) && deleteDatabase){
//context.deleteDatabase(FeedReaderDbHelper.DATABASE_NAME);
//dbHelper.onDrop(dbHelper.getWritableDatabase());
Expand Down Expand Up @@ -218,8 +218,6 @@ public void onResume() {
arrayAdapter = new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1, messageContentList);


new getMessagesFromDBTask().execute();

mMessageListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Expand All @@ -234,45 +232,27 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon

}

private class getMessagesFromDBTask extends AsyncTask<Void, Void, Void> {

private class GetMessageFromDBThread implements Runnable{
private List<Message> auxList;



public getMessagesFromDBTask() {
auxList = new ArrayList<>();
}

@Override
protected void onPreExecute() {
super.onPreExecute();
}
public void run() {
auxList = new ArrayList<>();

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getActivity());
List<Message> dbMessages = dbHelper.getAllNearbyMessages();

mMessageListView.setAdapter(arrayAdapter);
mMessageList.clear();
for(Message m: auxList){
messageContentList.clear();
for(Message m: dbMessages){
mMessageList.add(m);
messageContentList.add(m.getContent());
}
arrayAdapter.notifyDataSetChanged();
//Log.d("MessageLocationActivity","notify dataset changed");

}

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getActivity());
List<Message> dbMessages = dbHelper.getAllNearbyMessages();

for(Message m: dbMessages){
auxList.add(m);
}
return null;
arrayAdapter.notifyDataSetChanged();
handler.postDelayed(this,5000);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
Expand Down Expand Up @@ -281,7 +282,7 @@ public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
emails.add(cursor.getString(ProfileQuery.ADDRESS));
cursor.moveToNext();
}

cursor.close();
addEmailsToAutoComplete(emails);
}

Expand Down Expand Up @@ -327,7 +328,6 @@ public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {

@Override
protected Boolean doInBackground(Void... params) {
// TODO: attempt authentication against a network service.

try {

Expand All @@ -341,6 +341,7 @@ public void onHTTPResponse(Boolean response) {
ServicesDataHolder servicesDataHolder = ServicesDataHolder.getInstance();
servicesDataHolder.setUsername(mUsername);
servicesDataHolder.setPassword(mPassword);
Log.d(TAG, "onHTTPResponse: Username:"+servicesDataHolder.getUsername()+" P: "+servicesDataHolder.getPassword());
Intent intent = new Intent(mActivity,MainActivity.class);
startActivity(intent);

Expand All @@ -357,18 +358,6 @@ public void onHTTPResponse(Boolean response) {
return false;
}

for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mUsername)) {
// Account exists, return true if the password matches.
if(pieces[1].equals(mPassword)){
ServicesDataHolder dataHolder = ServicesDataHolder.getInstance();
dataHolder.setUsername(mUsername);
}

return true;
}
}

// TODO: register the new account here.
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import android.widget.TextView;

import pt.ulisboa.tecnico.cmu.tg14.locmessclient.DataObjects.ServicesDataHolder;
import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Services.BluetoothService;
import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Services.DBService;
import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Services.GPSService;
import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Services.MasterService;
import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Services.WifiService;
import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Utils.FeedReaderDbHelper;

import pt.ulisboa.tecnico.cmu.tg14.locmessclient.Utils.Network.ServerActions;
Expand Down Expand Up @@ -207,6 +212,16 @@ public void onClick(DialogInterface dialog,int id) {
return true;
}

@Override
protected void onStop() {
super.onStop();
stopService(new Intent(this,GPSService.class));
stopService(new Intent(this,WifiService.class));
stopService(new Intent(this,BluetoothService.class));
stopService(new Intent(this,DBService.class));
stopService(new Intent(this, MasterService.class));
}

@Override
public void onFragmentInteraction(Uri uri) {
//Log.d("URI",uri.toString());
Expand All @@ -215,9 +230,16 @@ public void onFragmentInteraction(Uri uri) {
private void logout() {
// delete all sensitive data from database
// TODO : do I need to stop services?
// TODO : >>>>> PUT THIS ON ASSYNCTASK <<<<<
new FeedReaderDbHelper(getApplicationContext()).dropDatabase(activity);
new ServerActions(activity).logout();
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getApplicationContext());
// dbHelper.dropDatabase(activity);
dbHelper.deleteAll();
ServiceManager serviceManager = ServiceManager.getInstance();
serviceManager.stopServices();
ServicesDataHolder dataHolder = ServicesDataHolder.getInstance();
dataHolder.setUsername("");
dataHolder.setPassword("");


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(activity);
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(activity);
List<String> dbLocationNames = dbHelper.getAllLocationsNames();

for(String s: dbLocationNames){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void onCreate(Bundle savedInstanceState) {

activity = this;

dbHelper = new FeedReaderDbHelper(activity);
dbHelper = FeedReaderDbHelper.getInstance(activity);


mKey = (EditText) findViewById(R.id.message_profile_key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getApplicationContext());
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getApplicationContext());
Message dbMessage = null;
try {
dbMessage = dbHelper.getMessage(messageID.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void onItemClick(AdapterView<?> adapterView, final View view, final int p
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, final View view, final int position, long l) {
final FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getActivity());
final FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getActivity());
final String messageContent = messagesList.get(position);

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
Expand Down Expand Up @@ -260,7 +260,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getActivity());
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getActivity());

String username = ServicesDataHolder.getInstance().getUsername();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getActivity());
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getActivity());
List<Profile> profilesList = dbHelper.getMyProfiles();

for(Profile p: profilesList){
Expand Down Expand Up @@ -244,7 +244,7 @@ protected void onPostExecute(Void aVoid) {

@Override
protected Void doInBackground(Void... params) {
FeedReaderDbHelper dbHelper = new FeedReaderDbHelper(getActivity());
FeedReaderDbHelper dbHelper = FeedReaderDbHelper.getInstance(getActivity());
try {
dbHelper.deleteProfileInTheFuture(k);
} catch (ProfileNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
emails.add(cursor.getString(ProfileQuery.ADDRESS));
cursor.moveToNext();
}
cursor.close();

addEmailsToAutoComplete(emails);
}
Expand Down
Loading

0 comments on commit 2c7f1fe

Please sign in to comment.