mirror of
https://github.com/ChronosX88/Influence.git
synced 2024-11-23 18:12: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 username = "";
|
||||||
public String password = "";
|
public String password = "";
|
||||||
public String jabberHost = "";
|
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();
|
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) {
|
if(connection == null) {
|
||||||
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
|
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
|
||||||
.setXmppDomain(credentials.jabberHost)
|
.setXmppDomain(credentials.jabberHost)
|
||||||
|
@ -74,6 +74,8 @@ public class XMPPConnectionService extends Service {
|
|||||||
if(connection != null) {
|
if(connection != null) {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
connection = null;
|
connection = null;
|
||||||
|
thread.interrupt();
|
||||||
|
thread = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -87,10 +89,12 @@ public class XMPPConnectionService extends Service {
|
|||||||
} catch (IOException | SmackException e) {
|
} catch (IOException | SmackException e) {
|
||||||
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.NETWORK_ERROR));
|
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.NETWORK_ERROR));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
onServiceStop();
|
||||||
stopSelf();
|
stopSelf();
|
||||||
} catch (XMPPException e) {
|
} catch (XMPPException | EmptyLoginCredentialsException e) {
|
||||||
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.INCORRECT_LOGIN_OR_PASSWORD));
|
EventBus.getDefault().post(new AuthenticationStatusEvent(AuthenticationStatusEvent.INCORRECT_LOGIN_OR_PASSWORD));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
onServiceStop();
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package io.github.chronosx88.influence.helpers;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@ -31,6 +32,7 @@ public class AppHelper extends MultiDexApplication {
|
|||||||
private static XMPPConnection xmppConnection;
|
private static XMPPConnection xmppConnection;
|
||||||
private static LoginCredentials currentLoginCredentials;
|
private static LoginCredentials currentLoginCredentials;
|
||||||
private static Handler mainUIThreadHandler;
|
private static Handler mainUIThreadHandler;
|
||||||
|
private static ServiceConnection serviceConnection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -103,4 +105,12 @@ public class AppHelper extends MultiDexApplication {
|
|||||||
public static Handler getMainUIThread() {
|
public static Handler getMainUIThread() {
|
||||||
return mainUIThreadHandler;
|
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 java9.util.concurrent.CompletableFuture
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import org.jxmpp.jid.EntityBareJid
|
import org.jxmpp.jid.EntityBareJid
|
||||||
import org.jxmpp.jid.impl.JidCreate
|
import org.jxmpp.jid.impl.JidCreate
|
||||||
import org.jxmpp.stringprep.XmppStringprepException
|
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) {
|
public fun onNewMessage(event: NewMessageEvent) {
|
||||||
if(event.chatID.equals(chatEntity!!.jid)) {
|
if(event.chatID.equals(chatEntity!!.jid)) {
|
||||||
val messageID = event.messageID
|
val messageID = event.messageID
|
||||||
|
@ -18,8 +18,12 @@
|
|||||||
package io.github.chronosx88.influence.views;
|
package io.github.chronosx88.influence.views;
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -62,7 +66,7 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
|||||||
passwordInputLayout.setErrorEnabled(true);
|
passwordInputLayout.setErrorEnabled(true);
|
||||||
|
|
||||||
signInButton = findViewById(R.id.sign_in_button);
|
signInButton = findViewById(R.id.sign_in_button);
|
||||||
progressDialog = new ProgressDialog(LoginActivity.this);
|
progressDialog = new ProgressDialog(LoginActivity.this, R.style.AlertDialogTheme);
|
||||||
progressDialog.setCancelable(false);
|
progressDialog.setCancelable(false);
|
||||||
progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
|
progressDialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
|
||||||
signInButton.setOnClickListener((v) -> {
|
signInButton.setOnClickListener((v) -> {
|
||||||
@ -71,6 +75,7 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
|||||||
doLogin();
|
doLogin();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,7 +131,7 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
|||||||
private void saveLoginCredentials() {
|
private void saveLoginCredentials() {
|
||||||
AppHelper.getPreferences().edit()
|
AppHelper.getPreferences().edit()
|
||||||
.putString("jid", jidEditText.getText().toString())
|
.putString("jid", jidEditText.getText().toString())
|
||||||
.putString("pass", HashUtils.sha1(passwordEditText.getText().toString()))
|
.putString("pass", passwordEditText.getText().toString())
|
||||||
.putBoolean("logged_in", true)
|
.putBoolean("logged_in", true)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
@ -134,6 +139,20 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
|||||||
private void doLogin() {
|
private void doLogin() {
|
||||||
loadingScreen(true);
|
loadingScreen(true);
|
||||||
startService(new Intent(this, XMPPConnectionService.class));
|
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)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
@ -158,14 +177,8 @@ public class LoginActivity extends AppCompatActivity implements CoreContracts.IL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onDestroy() {
|
||||||
super.onStart();
|
super.onDestroy();
|
||||||
EventBus.getDefault().register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
EventBus.getDefault().unregister(this);
|
EventBus.getDefault().unregister(this);
|
||||||
super.onStop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user