Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
fix logout crash (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacqueline8711 authored and kordianbruck committed Apr 22, 2019
1 parent a867d76 commit 354c4d8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
Expand Down Expand Up @@ -285,7 +286,7 @@ public boolean onPreferenceClick(Preference preference) {
startActivity(new Intent(getContext(), SetupEduroamActivity.class));
break;
case BUTTON_LOGOUT:
showLogoutDialog();
showLogoutDialog(R.string.logout_title, R.string.logout_message);
break;
default:
return false;
Expand All @@ -294,9 +295,10 @@ public boolean onPreferenceClick(Preference preference) {
return true;
}

private void showLogoutDialog() {
private void showLogoutDialog(int title, int message) {
AlertDialog dialog = new AlertDialog.Builder(mContext)
.setMessage(R.string.logout_message)
.setTitle(title)
.setMessage(message)
.setPositiveButton(R.string.logout, ((dialogInterface, i) -> logout()))
.setNegativeButton(R.string.cancel, null)
.create();
Expand All @@ -309,12 +311,20 @@ private void showLogoutDialog() {
}

private void logout() {
clearData();

try {
clearData();
} catch (Exception e) {
Utils.log(e);
showLogoutDialog(R.string.logout_error_title, R.string.logout_try_again);
return;
}

startActivity(new Intent(mContext, StartupActivity.class));
mContext.finish();
}

private void clearData() {
private void clearData() throws ExecutionException, InterruptedException {
TcaDb.resetDb(mContext);

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/de/tum/in/tumcampusapp/database/TcaDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;

import java.util.concurrent.ExecutionException;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
Expand All @@ -26,13 +28,11 @@
import de.tum.in.tumcampusapp.component.tumui.lectures.model.RoomLocations;
import de.tum.in.tumcampusapp.component.ui.alarm.model.FcmNotification;
import de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaDao;
import de.tum.in.tumcampusapp.component.ui.openinghour.LocationDao;
import de.tum.in.tumcampusapp.component.ui.cafeteria.CafeteriaMenuDao;
import de.tum.in.tumcampusapp.component.ui.cafeteria.FavoriteDishDao;
import de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria;
import de.tum.in.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu;
import de.tum.in.tumcampusapp.component.ui.cafeteria.model.FavoriteDish;
import de.tum.in.tumcampusapp.component.ui.openinghour.model.Location;
import de.tum.in.tumcampusapp.component.ui.chat.ChatMessageDao;
import de.tum.in.tumcampusapp.component.ui.chat.ChatRoomDao;
import de.tum.in.tumcampusapp.component.ui.chat.model.ChatMessage;
Expand All @@ -41,6 +41,8 @@
import de.tum.in.tumcampusapp.component.ui.news.NewsSourcesDao;
import de.tum.in.tumcampusapp.component.ui.news.model.News;
import de.tum.in.tumcampusapp.component.ui.news.model.NewsSources;
import de.tum.in.tumcampusapp.component.ui.openinghour.LocationDao;
import de.tum.in.tumcampusapp.component.ui.openinghour.model.Location;
import de.tum.in.tumcampusapp.component.ui.studyroom.StudyRoomDao;
import de.tum.in.tumcampusapp.component.ui.studyroom.StudyRoomGroupDao;
import de.tum.in.tumcampusapp.component.ui.studyroom.model.StudyRoom;
Expand All @@ -61,7 +63,6 @@
import de.tum.in.tumcampusapp.database.migrations.Migration3to4;
import de.tum.in.tumcampusapp.utils.CacheManager;
import de.tum.in.tumcampusapp.utils.Const;
import de.tum.in.tumcampusapp.utils.Utils;
import de.tum.in.tumcampusapp.utils.sync.SyncDao;
import de.tum.in.tumcampusapp.utils.sync.model.Sync;

Expand Down Expand Up @@ -168,13 +169,10 @@ public static synchronized TcaDb getInstance(Context context) {
*
* @param c context
*/
public static void resetDb(Context c) {
public static void resetDb(Context c) throws ExecutionException, InterruptedException {
// Stop all work tasks in WorkManager, since they might access the DB
try {
WorkManager.getInstance().cancelAllWork().wait();
} catch (InterruptedException e) {
Utils.log(e);
}

WorkManager.getInstance().cancelAllWork().getResult().get();

// Clear our cache table
CacheManager cacheManager = new CacheManager(c);
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,9 @@ Signatur: %5$s</string>
<string name="including_format_string">inklusive %s</string>
<string name="logout">Abmelden</string>
<string name="logout_message">Bist du sicher, dass du dich abmelden willst?</string>
<string name="logout_title">Verbindung zu TUMonline löschen</string>
<string name="logout_error_title">Logout ist fehlgeschlagen</string>
<string name="logout_try_again">Erneut versuchen?</string>
<string name="chat_message_send_error">Nachricht konnte nicht gesendet werden</string>
<string name="chat_message_try_again">Die Nachricht konnte nicht gesendet werden. Erneut versuchen?</string>
<string name="leave">Verlassen</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
<string name="open_wizard_detail">The Startup-Wizard helps you in order to set the basic preferences for accessing TUMonline services and the layout of this App.</string>
<string name="account" translatable="false">Account</string>
<string name="logout">Log out</string>
<string name="logout_title">Disconnect from TUMonline</string>
<string name="logout_message">Are you sure you want to log out?</string>
<string name="logout_error_title">Logout failed</string>
<string name="logout_try_again">Do you want to try again?</string>
<string name="employee_mode">Employee Mode</string>
<string name="employee_mode_info">Some unnecessary items like grades and tuition fees are hidden in this mode.</string>
<string name="clear_cache">Clear Cache</string>
Expand Down

0 comments on commit 354c4d8

Please sign in to comment.