This commit is contained in:
Lyndon
2017-10-12 20:43:33 +02:00
parent e5417ff1c6
commit 63b290e345
12 changed files with 53 additions and 13 deletions

View File

@@ -17,4 +17,5 @@ public interface AppPrefsConstants {
String APP_KILLED = "app_killed";
String UPLOAD_MAX_SIZE = "upload_max_size";
String IS_EMPLOYEE = "is_employee";
String SHOW_LOGIN_AGAIN = "show_login_again";
}

View File

@@ -52,6 +52,7 @@ public class ApiModule {
} else {
interceptor.setLevel(HttpLoggingInterceptor.Level.NONE);
}
return interceptor;
}
@@ -65,12 +66,15 @@ public class ApiModule {
if (token.isSet()) {
builder.addHeader("Token", token.get());
}
if (customerId.isSet()) {
builder.addHeader("CustomerID", customerId.get());
}
if (isHeaderSet) {
return chain.proceed(builder.build());
}
return chain.proceed(original.newBuilder().build());
};
}

View File

@@ -6,7 +6,6 @@ import com.p3.bewoplaner.data.api.responses.ProfileResponse;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.Path;
import rx.Observable;

View File

@@ -123,4 +123,11 @@ public class AppPrefsModule {
BooleanPreference provideIsEmployee(@AppPrefs SharedPreferences sharedPreferences) {
return new BooleanPreference(sharedPreferences, AppPrefsConstants.IS_EMPLOYEE);
}
@Provides
@ApplicationScope
@Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
BooleanPreference provideShowLoginAgain(@AppPrefs SharedPreferences sharedPreferences) {
return new BooleanPreference(sharedPreferences, AppPrefsConstants.SHOW_LOGIN_AGAIN);
}
}

View File

@@ -82,6 +82,9 @@ public interface ApplicationComponent {
@Named(AppPrefsConstants.IS_EMPLOYEE)
BooleanPreference provideIsEmployee();
@Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
BooleanPreference provideShowLoginAgain();
NotificationManager provideNotificationManager();
GroupRealmRepository provideGroupRealmRepository();

View File

@@ -280,7 +280,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
@Override
protected void onResume() {
super.onResume();
// mLoginPresenter.checkIfVoucherStillAvailable(this);
}
@Override
@@ -323,7 +322,7 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
}
@Override
public void logoutDirectly() {
public void logoutDirectly(boolean clearAllPrefs) {
EventBus.getDefault().post(new LogoutDirectlyEvent());
finish();
}
@@ -359,7 +358,6 @@ abstract class BaseChatActivity extends RuntimePermissionActivity implements Cha
@Override
public void resendMessage(Message message) {
// mLoginPresenter.checkIfVoucherStillAvailable(this);
if (!mChatPresenter.isAttached()) {
mChatPresenter.attachView(this);
}

View File

@@ -267,10 +267,12 @@ public class ChatPresenter extends MVPAbstractPresenter<ChatView>
Log.e(ChatPresenter.class.getSimpleName(), throwable.getMessage(), throwable);
getView().hideLoading();
getView().hideMessagesLoading();
if (mSystemUtils.isNetworkUnavailable()) {
getView().showError(R.string.error_no_internet_connection);
return;
}
getView().showError(R.string.error_something_went_wrong);
}

View File

@@ -6,6 +6,7 @@ import com.p3.bewoplaner.BewoplanerApplication;
import com.p3.bewoplaner.R;
import com.p3.bewoplaner.data.AppPrefsConstants;
import com.p3.bewoplaner.data.prefs.AppPrefs;
import com.p3.bewoplaner.data.prefs.BooleanPreference;
import com.p3.bewoplaner.di.InjectionHelper;
import com.p3.bewoplaner.page.main.MainActivity;
import com.p3.bewoplaner.utils.AppStoppedService;
@@ -31,6 +32,7 @@ import android.widget.ProgressBar;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -57,6 +59,10 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
@BindView(R.id.login_save_password_checkBox)
CheckBox mSavePasswordCheckbox;
@Inject
@Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
BooleanPreference mShowLoginAgainPreference;
@Inject
LoginPresenter mLoginPresenter;
@@ -76,6 +82,12 @@ public class LoginActivity extends AppCompatActivity implements LoginView {
mLoginPresenter.attachView(this);
decryptPreference();
ViewUtils.setProgressBarColor(mProgressBar, R.color.colorDefault);
if(mShowLoginAgainPreference.get()) {
mShowLoginAgainPreference.set(false);
showError(R.string.login_again);
}
mCallback.logout(Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID), true, null);
}

View File

@@ -64,6 +64,10 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Inject
RegisterService mRegisterService;
@Inject
@Named(AppPrefsConstants.SHOW_LOGIN_AGAIN)
BooleanPreference mShowLoginAgainPreference;
@Inject
@Named(AppPrefsConstants.API_ENDPOINT)
StringPreference mApiEndpointPreference;
@@ -451,6 +455,7 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Override
public void onNext(RegisterResponse registerResponse) {
Log.d(TAG, "onNext: " + registerResponse);
getView().showError("Topkek");
}
});
}
@@ -493,17 +498,24 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
@Override
public void onNext(JsonObject response) {
if (!response.has("result") || response.get("result") == null) {
logoutNavigation.logoutDirectly();
logoutNavigation.logoutDirectly(false);
return;
}
int result = response.get("result").getAsInt();
boolean shouldClearAllPrefs = false;
if(result == 0) {
deleteData(true);
shouldClearAllPrefs = true;
}
logoutNavigation.logoutDirectly();
if(result == 1) {
mShowLoginAgainPreference.set(true);
}
logoutNavigation.logoutDirectly(shouldClearAllPrefs);
}
});

View File

@@ -2,6 +2,6 @@ package com.p3.bewoplaner.page.main;
public interface LogoutNavigation {
void logoutDirectly();
void logoutDirectly(boolean clearAllPrefs);
}

View File

@@ -53,8 +53,7 @@ import de.hdodenhof.circleimageview.CircleImageView;
/**
* Created by imarneanu on 2/9/17.
*/
public class MainActivity extends AppCompatActivity
implements MainNavigation, LogoutNavigation {
public class MainActivity extends AppCompatActivity implements MainNavigation, LogoutNavigation {
private static final String REDIRECT_TO_CHAT = "redirect_to_chat";
private static final String BUNDLE = "bundle";
@@ -228,6 +227,7 @@ public class MainActivity extends AppCompatActivity
mLoginPresenter.logout(Settings.Secure.getString(MainActivity.this.getContentResolver(), Settings.Secure.ANDROID_ID), false, this);
},
(dialog, which) -> dialog.dismiss());
if (!isFinishing()) {
alertDialog.show();
}
@@ -241,8 +241,8 @@ public class MainActivity extends AppCompatActivity
}
@Override
public void logoutDirectly() {
mLoginPresenter.logout(Settings.Secure.getString(MainActivity.this.getContentResolver(), Settings.Secure.ANDROID_ID), true, this);
public void logoutDirectly(boolean clearAllPrefs) {
mLoginPresenter.logout(Settings.Secure.getString(MainActivity.this.getContentResolver(), Settings.Secure.ANDROID_ID), clearAllPrefs, this);
}
@Override
@@ -251,7 +251,9 @@ public class MainActivity extends AppCompatActivity
return;
}
startActivity(new Intent(MainActivity.this, LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
Intent intent = new Intent(MainActivity.this, LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
@@ -265,7 +267,7 @@ public class MainActivity extends AppCompatActivity
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onLogoutDirectlyEvent(LogoutDirectlyEvent logoutDirectlyEvent) {
logoutDirectly();
logoutDirectly(true);
}
@Override