mirror of
https://github.com/ChronosX88/Influence.git
synced 2024-11-23 10:02:18 +00:00
Fixed bug with logging in (login activity not starting)
This commit is contained in:
parent
f2042abe81
commit
bc5583104f
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2019 ChronosX88
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.github.chronosx88.influence;
|
||||
|
||||
public class EmptyLoginCredentialsException extends Exception {
|
||||
}
|
@ -21,4 +21,8 @@ public class LoginCredentials {
|
||||
public String username = "";
|
||||
public String password = "";
|
||||
public String jabberHost = "";
|
||||
|
||||
public boolean isEmpty() {
|
||||
return username.equals("") && password.equals("") && jabberHost.equals("");
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,10 @@ public class XMPPConnection implements ConnectionListener {
|
||||
networkHandler = new NetworkHandler();
|
||||
}
|
||||
|
||||
public void connect() throws XMPPException, IOException, SmackException {
|
||||
public void connect() throws XMPPException, IOException, SmackException, EmptyLoginCredentialsException {
|
||||
if(credentials.isEmpty()) {
|
||||
throw new EmptyLoginCredentialsException();
|
||||
}
|
||||
if(connection == null) {
|
||||
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
|
||||
.setXmppDomain(credentials.jabberHost)
|
||||
|
@ -74,6 +74,8 @@ public class XMPPConnectionService extends Service {
|
||||
if(connection != null) {
|
||||
connection.disconnect();
|
||||
connection = null;
|
||||
thread.interrupt();
|
||||
thread = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -87,10 +89,12 @@ public class XMPPConnectionService extends Service {
|
||||
} catch (IOException | SmackException e) {
|
||||
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.NETWORK_ERROR));
|
||||
e.printStackTrace();
|
||||
onServiceStop();
|
||||
stopSelf();
|
||||
} catch (XMPPException e) {
|
||||
} catch (XMPPException | EmptyLoginCredentialsException e) {
|
||||
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.INCORRECT_LOGIN_OR_PASSWORD));
|
||||
e.printStackTrace();
|
||||
onServiceStop();
|
||||
stopSelf();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.chronosx88.influence.helpers;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -31,6 +32,7 @@ public class AppHelper extends MultiDexApplication {
|
||||
private static XMPPConnection xmppConnection;
|
||||
private static LoginCredentials currentLoginCredentials;
|
||||
private static Handler mainUIThreadHandler;
|
||||
private static ServiceConnection serviceConnection;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@ -103,4 +105,12 @@ public class AppHelper extends MultiDexApplication {
|
||||
public static Handler getMainUIThread() {
|
||||
return mainUIThreadHandler;
|
||||
}
|
||||
|
||||
public static ServiceConnection getServiceConnection() {
|
||||
return serviceConnection;
|
||||
}
|
||||
|
||||
public static void setServiceConnection(ServiceConnection serviceConnection) {
|
||||
AppHelper.serviceConnection = serviceConnection;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ import io.github.chronosx88.influence.models.roomEntities.MessageEntity
|
||||
import java9.util.concurrent.CompletableFuture
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import org.jxmpp.jid.EntityBareJid
|
||||
import org.jxmpp.jid.impl.JidCreate
|
||||
import org.jxmpp.stringprep.XmppStringprepException
|
||||
@ -77,7 +78,7 @@ class ChatPresenter(private val view: CoreContracts.IChatViewContract, private v
|
||||
//
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public fun onNewMessage(event: NewMessageEvent) {
|
||||
if(event.chatID.equals(chatEntity!!.jid)) {
|
||||
val messageID = event.messageID
|
||||
|
@ -18,8 +18,12 @@
|
||||
package io.github.chronosx88.influence.views;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
@ -62,7 +66,7 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
||||
passwordInputLayout.setErrorEnabled(true);
|
||||
|
||||
signInButton = findViewById(R.id.sign_in_button);
|
||||
progressDialog = new ProgressDialog(LoginActivity.this);
|
||||
progressDialog = new ProgressDialog(LoginActivity.this, R.style.AlertDialogTheme);
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
|
||||
signInButton.setOnClickListener((v) -> {
|
||||
@ -71,6 +75,7 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
||||
doLogin();
|
||||
}
|
||||
});
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,7 +131,7 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
||||
private void saveLoginCredentials() {
|
||||
AppHelper.getPreferences().edit()
|
||||
.putString("jid", jidEditText.getText().toString())
|
||||
.putString("pass", HashUtils.sha1(passwordEditText.getText().toString()))
|
||||
.putString("pass", passwordEditText.getText().toString())
|
||||
.putBoolean("logged_in", true)
|
||||
.apply();
|
||||
}
|
||||
@ -134,6 +139,20 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
||||
private void doLogin() {
|
||||
loadingScreen(true);
|
||||
startService(new Intent(this, XMPPConnectionService.class));
|
||||
ServiceConnection connection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
XMPPConnectionService.XMPPServiceBinder binder = (XMPPConnectionService.XMPPServiceBinder) service;
|
||||
AppHelper.setXmppConnection(binder.getConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
AppHelper.setXmppConnection(null);
|
||||
}
|
||||
};
|
||||
AppHelper.setServiceConnection(connection);
|
||||
bindService(new Intent(this, XMPPConnectionService.class), connection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
@ -158,14 +177,8 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
EventBus.getDefault().unregister(this);
|
||||
super.onStop();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user