forked from github/wulkanowy-mirror
Stop SyncJob if user is not registered in app (#113)
This commit is contained in:
parent
3000c077c4
commit
54e6aee82e
@ -118,12 +118,12 @@ public class AccountSync {
|
|||||||
daoSession.getSemesterDao().insertInTx(semesterList);
|
daoSession.getSemesterDao().insertInTx(semesterList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initLastUser() throws IOException, CryptoException {
|
public void initLastUser() throws CryptoException {
|
||||||
|
|
||||||
long userId = sharedPref.getCurrentUserId();
|
long userId = sharedPref.getCurrentUserId();
|
||||||
|
|
||||||
if (userId == 0) {
|
if (userId == 0) {
|
||||||
throw new IOException("Can't find saved user");
|
throw new NotRegisteredUserException("Can't find user id in SharedPreferences");
|
||||||
}
|
}
|
||||||
|
|
||||||
LogUtils.debug("Initialization current user id=" + userId);
|
LogUtils.debug("Initialization current user id=" + userId);
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.github.wulkanowy.data.sync;
|
||||||
|
|
||||||
|
public class NotRegisteredUserException extends RuntimeException {
|
||||||
|
|
||||||
|
public NotRegisteredUserException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ import io.github.wulkanowy.R;
|
|||||||
import io.github.wulkanowy.WulkanowyApp;
|
import io.github.wulkanowy.WulkanowyApp;
|
||||||
import io.github.wulkanowy.data.RepositoryContract;
|
import io.github.wulkanowy.data.RepositoryContract;
|
||||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||||
|
import io.github.wulkanowy.data.sync.NotRegisteredUserException;
|
||||||
import io.github.wulkanowy.services.notifies.GradeNotify;
|
import io.github.wulkanowy.services.notifies.GradeNotify;
|
||||||
import io.github.wulkanowy.ui.main.MainActivity;
|
import io.github.wulkanowy.ui.main.MainActivity;
|
||||||
import io.github.wulkanowy.utils.LogUtils;
|
import io.github.wulkanowy.utils.LogUtils;
|
||||||
@ -74,9 +75,12 @@ public class SyncJob extends SimpleJobService {
|
|||||||
showNotification();
|
showNotification();
|
||||||
}
|
}
|
||||||
return JobService.RESULT_SUCCESS;
|
return JobService.RESULT_SUCCESS;
|
||||||
|
} catch (NotRegisteredUserException e) {
|
||||||
|
logError(e);
|
||||||
|
stop(getApplicationContext());
|
||||||
|
return JobService.RESULT_FAIL_NORETRY;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Crashlytics.logException(e);
|
logError(e);
|
||||||
LogUtils.error("During background synchronization an error occurred", e);
|
|
||||||
return JobService.RESULT_FAIL_RETRY;
|
return JobService.RESULT_FAIL_RETRY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,4 +120,9 @@ public class SyncJob extends SimpleJobService {
|
|||||||
gradeList.size(), gradeList.size());
|
gradeList.size(), gradeList.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logError(Exception e) {
|
||||||
|
Crashlytics.logException(e);
|
||||||
|
LogUtils.error("During background synchronization an error occurred", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.os.Bundle;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
|
||||||
import io.github.wulkanowy.services.notifies.NotificationService;
|
import io.github.wulkanowy.services.notifies.NotificationService;
|
||||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||||
import io.github.wulkanowy.ui.login.LoginActivity;
|
import io.github.wulkanowy.ui.login.LoginActivity;
|
||||||
@ -48,9 +47,4 @@ public class SplashActivity extends BaseActivity implements SplashContract.View
|
|||||||
public void cancelNotifications() {
|
public void cancelNotifications() {
|
||||||
new NotificationService(getApplicationContext()).cancelAll();
|
new NotificationService(getApplicationContext()).cancelAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopSyncService() {
|
|
||||||
SyncJob.stop(getApplicationContext());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@ public interface SplashContract {
|
|||||||
void openMainActivity();
|
void openMainActivity();
|
||||||
|
|
||||||
void cancelNotifications();
|
void cancelNotifications();
|
||||||
|
|
||||||
void stopSyncService();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PerActivity
|
@PerActivity
|
||||||
|
@ -24,7 +24,6 @@ public class SplashPresenter extends BasePresenter<SplashContract.View>
|
|||||||
getView().openMainActivity();
|
getView().openMainActivity();
|
||||||
} else {
|
} else {
|
||||||
getView().openLoginActivity();
|
getView().openLoginActivity();
|
||||||
getView().stopSyncService();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user