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();
}
......
package de.uni_oldenburg.bidl.listfragment;
import android.app.Activity;
import android.content.Context;
import android.support.v4.app.ListFragment;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
......@@ -9,10 +8,12 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import classes.MyList;
import classes.apps.forum.CommentList;
import de.uni_oldenburg.bidl.R;
import services.ViewHelper.SwipeDismissListViewTouchListener;
/**
* Created by Christof on 01.09.2016.
......@@ -64,8 +65,20 @@ public class SuperListFragment extends ListFragment implements SwipeRefreshLayou
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (withSwipe){
//ToDo: das Löschen von Daten durch swipen realisieren.
if (withSwipe) {
SwipeDismissListViewTouchListener swipeListener = new SwipeDismissListViewTouchListener(this.getListView(), new SwipeDismissListViewTouchListener.DismissCallbacks() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
communicator.onSwipeDismiss(listView, reverseSortedPositions);
}
});
this.getListView().setOnTouchListener(swipeListener);
this.getListView().setOnScrollListener(swipeListener.makeScrollListener());
}
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipelayout);
if (isRefreshable){
......@@ -108,6 +121,7 @@ public class SuperListFragment extends ListFragment implements SwipeRefreshLayou
this.communicator = null;
}
@Override
public void onRefresh() {
communicator.updateFragList();
......
......@@ -2,7 +2,6 @@ package de.uni_oldenburg.bidl.member_view;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
......@@ -14,28 +13,34 @@ import de.uni_oldenburg.bidl.R;
import services.servercommunication.NetworkService;
public class ChangePasswordActivity extends AppCompatActivity {
/**
* Tag for loggin
**/
private static final String TAG = ChangePasswordActivity.class.getSimpleName();
// Values
/**
* GUI
**/
private EditText newPasswordEditText;
private EditText currentPasswordEditText;
private EditText repeatPasswordEditText;
private Button changePasswordButton;
/**
* values
**/
private User user;
private String newPassword;
private String currentPassword;
private String repeatPassword;
private Boolean equalPassword;
// GUI
private EditText newPasswordEditText;
private EditText currentPasswordEditText;
private EditText repeatPasswordEditText;
private Button changePasswordButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_password);
LocalStorage storage = new LocalStorage(this);
this.user = storage.getLoggedInUser();
......@@ -47,28 +52,30 @@ public class ChangePasswordActivity extends AppCompatActivity {
}
public void changePassword(View view) {
// hole aktuelles Passwort
// get current Password
currentPassword = currentPasswordEditText.getText().toString();
// hole neues Passwort
// get new Password
newPassword = newPasswordEditText.getText().toString();
// hole das neue Passwort, wiederholt
// repeat new Password
repeatPassword = repeatPasswordEditText.getText().toString();
// vergleiche Passwörter
// compare Passwords
equalPassword = newPassword.equals(repeatPassword);
if(currentPassword.isEmpty() || newPassword.isEmpty() || repeatPassword.isEmpty()) {
if (currentPassword.isEmpty() || newPassword.isEmpty() || repeatPassword.isEmpty()) {
toastMessage(getString(R.string.enterPassword));
}
else if (equalPassword){
} else if (equalPassword) {
NetworkService.changePassword((int) user.getUserId(), currentPassword, newPassword, new NetworkService.RequestChangePasswordHandler() {
@Override
public void done(String response) {
if (response.equals("ok")) {
switch (response) {
case "ok":
toastMessage(getString(R.string.profil_passwordChangeSuccess));
} else if (response.equals("error")) {
break;
case "error":
toastMessage(getString(R.string.profil_passwordChangeFail));
} else {
break;
default:
toastMessage(getString(R.string.register_response_noconnection));
break;
}
}
......@@ -79,9 +86,11 @@ public class ChangePasswordActivity extends AppCompatActivity {
}
/**
* Zeigt eine Toastmessage an
* @param message Nachricht, die angezeigt werden soll
* Show Toastmessage
*
* @param message which should be displayed
*/
protected void toastMessage(final String message) {
this.runOnUiThread(new Runnable() {
......
package de.uni_oldenburg.bidl.member_view;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ListPopupWindow;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import classes.LocalStorage;
import classes.User;
import classes.apps.event.Event;
import classes.apps.event.Favorite;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import de.uni_oldenburg.bidl.listfragment.EventTimeAdapter;
import services.ViewHelper.SwipeDismissListViewTouchListener;
import services.db.DBHelper;
import services.servercommunication.NetworkService;
public class FavoriteActivity extends AppCompatActivity {
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.ListPopupWindow;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import classes.LocalStorage;
import classes.User;
import classes.apps.event.Favorite;
import de.uni_oldenburg.bidl.BaseActivity;
import de.uni_oldenburg.bidl.R;
import de.uni_oldenburg.bidl.home_view.MainActivity;
import de.uni_oldenburg.bidl.listfragment.EventTimeAdapter;
import services.ViewHelper.SwipeDismissListViewTouchListener;
import services.servercommunication.NetworkService;
public class FavoriteActivity extends BaseActivity {
/**
* GUI
**/
private ListView listView;
/**
* values
**/
private ArrayAdapter<String> adapter;
protected LocalStorage localStorage;
private User user;
private List<Favorite> favoriteList;
@Override
......@@ -47,18 +41,21 @@ public class FavoriteActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_favorite);
/** init GUI **/
listView = (ListView) findViewById(R.id.favoriteListView);
this.localStorage = new LocalStorage(this);
user = localStorage.getLoggedInUser();
getFavoritesFromServer(user.getUserId());
setMenu(R.id.drawer_layout_favorite);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);