Commit a9c70991 authored by Christof Wolke's avatar Christof Wolke

code formatiert, beschreibungen ergänzt und letzte bugs behoben

parent 4d0d3c8f
......@@ -83,7 +83,7 @@
android:label="@string/title_activity_search"
android:screenOrientation="sensorPortrait" />
<activity
android:name=".member_view.ProfilActivity"
android:name=".member_view.ProfileActivity"
android:label="@string/title_activity_profil"
android:screenOrientation="sensorPortrait" />
<activity android:name=".member_view.ChangePasswordActivity" />
......
......@@ -3,7 +3,6 @@ package classes;
import android.content.Context;
import android.content.SharedPreferences;
import co.uk.rushorm.core.RushCore;
/**
* Created by Christof on 25.08.2016.
......@@ -85,15 +84,6 @@ public class LocalStorage {
return this.userLocalDatabase.getString("image", "");
}
/**
* Ändert den Pfad zum Profilbild des Nutzers
* @param image neuen Pfad zum Profilbild des Nutzers
*/
public void setUserImage(String image) {
SharedPreferences.Editor spEditor = this.userLocalDatabase.edit();
spEditor.putString("image", image);
spEditor.apply();
}
/**
......
......@@ -2,7 +2,20 @@ package de.uni_oldenburg.bidl;
import android.app.Application;
import java.util.ArrayList;
import java.util.List;
import classes.apps.event.Event;
import classes.apps.event.EventTime;
import classes.apps.event.Favorite;
import classes.apps.feedback.Feedback;
import classes.apps.feedback.Question;
import classes.apps.forum.Comment;
import classes.apps.forum.CommentList;
import classes.apps.forum.Forum;
import classes.apps.materials.Materials;
import co.uk.rushorm.android.AndroidInitializeConfig;
import co.uk.rushorm.core.Rush;
import co.uk.rushorm.core.RushCore;
/**
......@@ -21,7 +34,22 @@ public class AppClass extends Application {
* */
//this.deleteDatabase("bidl.db");
AndroidInitializeConfig config = new AndroidInitializeConfig(getApplicationContext());
List<Class<? extends Rush>> classes = new ArrayList<>();
// Add classes
classes.add(Event.class);
classes.add(EventTime.class);
classes.add(Favorite.class);
classes.add(Feedback.class);
classes.add(Question.class);
classes.add(Comment.class);
classes.add(Forum.class);
classes.add(Materials.class);
AndroidInitializeConfig config = new AndroidInitializeConfig(this);
config.setClasses(classes);
RushCore.initialize(config);
}
}
package de.uni_oldenburg.bidl;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
......@@ -17,20 +18,20 @@ import classes.LocalStorage;
import de.uni_oldenburg.bidl.guest_view.LoginActivity;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import de.uni_oldenburg.bidl.member_view.FavoriteActivity;
import de.uni_oldenburg.bidl.member_view.ProfilActivity;
import de.uni_oldenburg.bidl.member_view.ProfileActivity;
import de.uni_oldenburg.bidl.member_view.SearchActivity;
import services.db.DBHelper;
/**
* Created by Christof on 30.08.2016.
* BaseActivity for each Activity, which has an menu
*/
public class BaseActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
public class BaseActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
protected LocalStorage localStorage;
protected int drawerLayout;
@SuppressWarnings("deprecation")
protected void setMenu(int drawer_layout) {
setDrawerLayout(drawer_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
......@@ -51,19 +52,27 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(drawerLayout);
if (drawer != null) {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
} else {
super.onBackPressed();
}
}
/**
* Menu
*
* @param item clicked menuItem
* @return true
*/
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
......@@ -75,7 +84,7 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
toProfilActivity();
} else if (id == R.id.nav_favorite) {
toFavoriteAcitvity();
} else if (id == R.id.nav_logout){
} else if (id == R.id.nav_logout) {
toLoginActivity();
} else if (id == R.id.nav_share) {
shareEvent();
......@@ -91,7 +100,7 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
}
private void toProfilActivity() {
startActivity(new Intent(this, ProfilActivity.class));
startActivity(new Intent(this, ProfileActivity.class));
}
private void toSearchActivity() {
......@@ -102,9 +111,9 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
Event event = DBHelper.getEvent();
if(event != null ){
if (event.getCurrentEnd() >= getCurrentTime()){
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich sitze gerade in der Veranstaltung "+event.getName()+".");
if (event != null) {
if (event.getCurrentEnd() >= getCurrentTime()) {
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich sitze gerade in der Veranstaltung " + event.getName() + ".");
} else {
sendIntent.putExtra(Intent.EXTRA_TEXT, "Ich benutze gerade die Bidl App der Universität Oldenburg!");
}
......@@ -136,13 +145,15 @@ public class BaseActivity extends AppCompatActivity implements NavigationView.On
/**
* Get the current Time
*
* @return the current Time with the format from the Server
*/
@SuppressWarnings("deprecation")
public int getCurrentTime() {
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
int hour = date.getHours()*60;
int hour = date.getHours() * 60;
int minute = date.getMinutes();
return hour+minute;
return hour + minute;
}
}
......@@ -30,13 +30,11 @@ public class LoginActivity extends AppCompatActivity {
private Button btLogin;
private TextView tvRegister;
private LocalStorage localStorage;
/** values **/
private String email;
private String password;
private boolean keepLoggedIn;
private static final String TOAST_ERROR_MESSAGE = "Falsche Login Daten";
private LocalStorage localStorage;
......@@ -87,7 +85,7 @@ public class LoginActivity extends AppCompatActivity {
LoginActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), TOAST_ERROR_MESSAGE, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), getString(R.string.wrongLoginData), Toast.LENGTH_SHORT).show();
view.setEnabled(true);
}
});
......
......@@ -15,17 +15,23 @@ import services.servercommunication.NetworkService;
public class RegisterActivity extends AppCompatActivity {
/** GUI **/
/**
* GUI
**/
private EditText etUsername;
private EditText etEmail;
private EditText etPassword;
private EditText etRepeatPassword;
private Button btNewAccount;
private TextView tvToLogin;
/** values **/
/**
* values
**/
private String name;
private String email;
private String password;
private String repeatPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -36,6 +42,7 @@ public class RegisterActivity extends AppCompatActivity {
etUsername = (EditText) findViewById(R.id.etFullName);
etEmail = (EditText) findViewById(R.id.etEmail);
etPassword = (EditText) findViewById(R.id.etPassword);
etRepeatPassword = (EditText) findViewById(R.id.etRepeatPassword);
btNewAccount = (Button) findViewById(R.id.btRegister);
tvToLogin = (TextView) findViewById(R.id.link_to_login);
......@@ -46,17 +53,23 @@ public class RegisterActivity extends AppCompatActivity {
name = etUsername.getText().toString();
email = etEmail.getText().toString();
password = etPassword.getText().toString();
repeatPassword = etRepeatPassword.getText().toString();
if (!(name.isEmpty() || email.isEmpty() || password.isEmpty())){
if (isEmailOk()){
if (!(name.isEmpty() || email.isEmpty() || password.isEmpty() || repeatPassword.isEmpty())) {
if (isEmailOk()) {
if (isPasswordOk()) {
btNewAccount.setEnabled(false);
register(email, name, password);
toMainActivity();
}else {
} else {
showToastMessage(getString(R.string.register_response_passwordDontMatch));
}
} else {
showToastMessage(getString(R.string.register_response_emailNotOk));
}
}else{
} else {
showToastMessage(getString(R.string.register_response_fillOutAllFields));
}
......@@ -71,6 +84,14 @@ public class RegisterActivity extends AppCompatActivity {
});
}
/**
* check if Passwords are equal
*
* @return true: ok
*/
private boolean isPasswordOk() {
return password.equals(repeatPassword);
}
private void toMainActivity() {
......@@ -79,6 +100,7 @@ public class RegisterActivity extends AppCompatActivity {
/**
* checks, if the email is valid
*
* @return true: ok
*/
private boolean isEmailOk() {
......@@ -88,6 +110,7 @@ public class RegisterActivity extends AppCompatActivity {
/**
* Register a User in the DB.
*
* @param email Email from the USer.
* @param name Name of the new User.
* @param password Password from the User.
......@@ -121,6 +144,7 @@ public class RegisterActivity extends AppCompatActivity {
/**
* Shows the User different messages.
*
* @param message Toast message for the User.
*/
private void showToastMessage(final String message) {
......
......@@ -13,14 +13,20 @@ import services.servercommunication.NetworkService;
public class ResetPasswordActivity extends AppCompatActivity {
// Tag constant for Logging
/**
* Tag constant for Logging
**/
private static final String Tag = ResetPasswordActivity.class.getSimpleName();
// GUI
/**
* GUI
**/
private EditText resetPwEditText;
private Button resetPwButton;
// Values
/**
* values
**/
private String mail;
......@@ -35,35 +41,35 @@ public class ResetPasswordActivity extends AppCompatActivity {
}
public void resetPassword(View view){
public void resetPassword(View view) {
mail = resetPwEditText.getText().toString();
if (mail.isEmpty()){
if (mail.isEmpty()) {
Toast.makeText(getApplicationContext(), getString(R.string.resetPassword_emial),
Toast.LENGTH_SHORT).show();
}
else {
} else {
NetworkService.resetPassword(mail, new NetworkService.RequestResetPasswordHandler() {
@Override
public void done(final String statusResponse) {
ResetPasswordActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if (statusResponse.equals("ok")) {
switch (statusResponse) {
case "ok":
Toast.makeText(getApplicationContext(),
getString(R.string.resetPassword_success),
Toast.LENGTH_SHORT).show();
} else if (statusResponse.equals("error")) {
break;
case "error":
Toast.makeText(getApplicationContext(),
getString(R.string.resetPassword_error),
Toast.LENGTH_SHORT).show();
} else {
break;
default:
Toast.makeText(getApplicationContext(),
getString(R.string.register_response_noconnection),
Toast.LENGTH_SHORT).show();
break;
}
}
......@@ -77,7 +83,7 @@ public class ResetPasswordActivity extends AppCompatActivity {
}
public void onBackPressed(){
public void onBackPressed() {
startActivity(new Intent(this, LoginActivity.class));
finish();
}
......
......@@ -3,11 +3,9 @@ package de.uni_oldenburg.bidl.home_view;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.nfc.Tag;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
......@@ -22,9 +20,7 @@ import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -32,7 +28,6 @@ import java.util.UUID;
import classes.User;
import classes.apps.event.Event;
import classes.LocalStorage;
import classes.apps.event.Favorite;
import de.uni_oldenburg.bidl.BaseActivity;
import de.uni_oldenburg.bidl.R;
......@@ -41,24 +36,36 @@ import services.servercommunication.NetworkService;
public class MainActivity extends BaseActivity {
/** Tag for Logging **/
/**
* Tag for Logging
**/
private static final String TAG = MainActivity.class.getSimpleName();
/** Soll nach Beacons gesucht werden? **/
private static Boolean RANGING = true;
/**
* Soll nach Beacons gesucht werden?
**/
private Boolean ranging = true;
/** Package, wo die apps angelegt werden **/
/**
* Package, wo die apps angelegt werden
**/
private static final String appPackage = "de.uni_oldenburg.bidl.member_view.";
/** Estimote Beacon UUID **/
/**
* Estimote Beacon UUID
**/
private static UUID PROXIMITY_UUID;
/** GUI **/
/**
* GUI
**/
private GridView grid;
private TextView noBeaconTV;
/** values **/
/**
* values
**/
private Region region;
private BeaconManager beaconManager;
private Beacon nearestBeacon;
......@@ -69,9 +76,6 @@ public class MainActivity extends BaseActivity {
private HashMap<String, String> map;
private int currentEventEnd;
private int nextEventStart;
private ProgressDialog progress;
@Override
......@@ -87,9 +91,9 @@ public class MainActivity extends BaseActivity {
PROXIMITY_UUID = UUID.fromString(getResources().getString(R.string.ESTIMOTE_PROXIMITY_UUID));
this.localStorage = new LocalStorage(this);
/*Weiterleitung je nach Login Status */
if(!localStorage.isLoggedIn()){
/** Forwarding depending on LoginStatus **/
if (!localStorage.isLoggedIn()) {
startActivity(new Intent(this, LoginActivity.class));
this.finish();
} else {
......@@ -102,13 +106,13 @@ public class MainActivity extends BaseActivity {
beaconManager = new BeaconManager(this);
beaconManager.setForegroundScanPeriod(4000, 1000);
if (getIntent().getExtras() != null){
/** Get the Events from SearchActivity and FavoriteActivity **/
if (getIntent().getExtras() != null) {
setRanging(false);
if (getIntent().getSerializableExtra("event") != null){
if (getIntent().getSerializableExtra("event") != null) {
Event event = (Event) getIntent().getSerializableExtra("event");
initGui(event);
} else if (getIntent().getSerializableExtra("favorite") != null){
} else if (getIntent().getSerializableExtra("favorite") != null) {
Favorite favorite = (Favorite) getIntent().getSerializableExtra("favorite");
getEventById(favorite);
}
......@@ -118,7 +122,7 @@ public class MainActivity extends BaseActivity {
/**
* Start ranging for beacons.
**/
if(RANGING && isBluetoothAvailable()){
if (ranging && isBluetoothAvailable()) {
startRanging();
}
......@@ -127,63 +131,52 @@ public class MainActivity extends BaseActivity {
*/
makeGridItemClickable();
/**
* FloatingButton allows to add an Event to Favorites
*/
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabMain);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if(event != null) {
NetworkService.addFavorite(user.getUserId(), event.getEventId(), event.getName(),
event.getEventTimeList(), new NetworkService.AddFavoriteHandler() {
@Override
public void done(final String status) {
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, status);
if(status.equals("connection_error")){
showToastMessage(getString(R.string.noConnection));
} else if (status.equals("error")){
showToastMessage(getString(R.string.couldNotSaveFavorite));
} else{
Snackbar.make(view, event.getName() + " wurde zu Ihren Favoriten hinzugefügt!",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
addFavorite(view);
}
});
}
});
} else{
showToastMessage(getString(R.string.findEventToSaveAsFavorite));
}
@Override
protected void onResume() {
super.onResume();
// is Bluetooth on, is Location on, etc.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
setRanging(true);
// Start ranging for beacons, when the activity appears on the screen
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startRanging(region);
}
});
}
private void getEventById(Favorite favorite) {
NetworkService.getEventById(favorite.getFavoriteId(), new NetworkService.RequestGetEventByIdHandler() {
@Override
public void done(final Event event) {
MainActivity.this.runOnUiThread(new Runnable() {
/**
* Ranging ist stopped, if the Activity disappears.
*/
@Override
public void run() {
if (event != null){
setEvent(event);
initGui(event);
} else {
Toast.makeText(getApplicationContext(), getString(R.string.noConnection), Toast.LENGTH_SHORT).show();
}
}
});
}
});
public void onPause() {
beaconManager.stopRanging(region);
super.onPause();
}
/**
* Makes the small apps from an Event clickable and searches for the fitting activity
* !!! IMPORTANT: the classname from the Domain Model has to be the same name as the Activity !!!
* Example:
* Modelname = Forum.class
* --> then the Activityname has to be modelname+Acitvity= ForumAcitvity.
**/
private void makeGridItemClickable() {
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
......@@ -195,21 +188,22 @@ public class MainActivity extends BaseActivity {
Class<?> c = null;
try {
c = Class.forName(appPackage+app+"Activity");
c = Class.forName(appPackage + app + "Activity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Intent intent = new Intent(getApplicationContext(), c).putExtra("appName",appName);
Intent intent = new Intent(getApplicationContext(), c).putExtra("appName", appName);
startActivity(intent);
}
/** get the Classname from the Hashmap through the appname **/
private String getClassnameFromHashmap(String appName) {
for(Map.Entry<String,String> entry : map.entrySet()){
for (Map.Entry<String, String> entry : map.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value.equals(appName)){
if (value.equals(appName)) {
return key;
}
}
......@@ -218,13 +212,6 @@ public class MainActivity extends BaseActivity {
});
}
private void setProgressDialog() {
progress = new ProgressDialog(this);
progress.setTitle("Loading");
progress.setMessage("Wait while searching for Beacons...");
progress.show();