Logout users

This commit is contained in:
stom79 2019-01-29 14:08:02 +01:00
parent a181683355
commit 1bfa28078a
6 changed files with 79 additions and 31 deletions

View File

@ -97,11 +97,14 @@ public class LoginActivity extends BaseActivity {
private CheckBox peertube_instance;
private Button connectionButton;
private String actionToken;
private String autofilledInstance;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
if(b != null) {
autofilledInstance = b.getString("instance", null);
}
if( getIntent() != null && getIntent().getData() != null && getIntent().getData().toString().contains("mastalab://backtomastalab?code=")){
String url = getIntent().getData().toString();
String val[] = url.split("code=");
@ -190,6 +193,11 @@ public class LoginActivity extends BaseActivity {
info_2FA = findViewById(R.id.info_2FA);
peertube_instance = findViewById(R.id.peertube_instance);
if( autofilledInstance != null){
login_instance.setText(autofilledInstance.trim());
retrievesClientId();
login_uid.requestFocus();
}
peertube_instance.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

View File

@ -69,7 +69,7 @@ public class CrossActions {
private static List<Account> connectedAccounts(Context context, Status status, boolean limitedToOwner){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<Account> accountstmp = new AccountDAO(context, db).getAllAccount();
List<Account> accountstmp = new AccountDAO(context, db).getAllAccountCrossAction();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account currentAccount = new AccountDAO(context, db).getAccountByID(userId);
List<Account> accounts = new ArrayList<>();

View File

@ -1720,21 +1720,27 @@ public class Helper {
subActionButtonAcc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(Helper.PREF_KEY_ID, accountChoice.getId());
editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.commit();
if(accountChoice.getSocial() != null && accountChoice.getSocial().equals("PEERTUBE"))
Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct()), Toast.LENGTH_LONG).show();
else
Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct() + "@" + accountChoice.getInstance()), Toast.LENGTH_LONG).show();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.finish();
activity.startActivity(changeAccount);
if( !accountChoice.getToken().equals("null")) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(Helper.PREF_KEY_ID, accountChoice.getId());
editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.commit();
if (accountChoice.getSocial() != null && accountChoice.getSocial().equals("PEERTUBE"))
Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct()), Toast.LENGTH_LONG).show();
else
Toasty.info(activity, activity.getString(R.string.toast_account_changed, "@" + accountChoice.getAcct() + "@" + accountChoice.getInstance()), Toast.LENGTH_LONG).show();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.finish();
activity.startActivity(changeAccount);
}else{ //The account was logged out
Intent intent = new Intent(activity, LoginActivity.class);
intent.putExtra("instance", accountChoice.getInstance());
activity.startActivity(intent);
}
}
});
actionMenuAccBuilder.addSubActionView(subActionButtonAcc);
@ -1775,17 +1781,23 @@ public class Helper {
public void onClick(View v) {
for(final Account accountChoice: accounts) {
if (!currrentUserId.equals(accountChoice.getId())) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(Helper.PREF_KEY_ID, accountChoice.getId());
editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.commit();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.finish();
activity.startActivity(changeAccount);
if( !accountChoice.getToken().equals("null")) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, accountChoice.getToken());
editor.putString(Helper.PREF_KEY_ID, accountChoice.getId());
editor.putString(Helper.PREF_INSTANCE, accountChoice.getInstance().trim());
editor.putBoolean(Helper.PREF_IS_MODERATOR, accountChoice.isModerator());
editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, accountChoice.isAdmin());
editor.commit();
Intent changeAccount = new Intent(activity, MainActivity.class);
changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.finish();
activity.startActivity(changeAccount);
}else{ //The account was logged out
Intent intent = new Intent(activity, LoginActivity.class);
intent.putExtra("instance", accountChoice.getInstance());
activity.startActivity(intent);
}
}
}
}

View File

@ -125,7 +125,7 @@ public class NotificationsSyncJob extends Job {
return;
//If WIFI only and on WIFI OR user defined any connections to use the service.
if(!sharedpreferences.getBoolean(Helper.SET_WIFI_ONLY, false) || Helper.isOnWIFI(getContext())) {
List<Account> accounts = new AccountDAO(getContext(),db).getAllAccount();
List<Account> accounts = new AccountDAO(getContext(),db).getAllAccountCrossAction();
//It means there is no user in DB.
if( accounts == null )
return;

View File

@ -126,7 +126,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
}
it.remove();
}
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccount();
List<Account> accountStreams = new AccountDAO(getApplicationContext(), db).getAllAccountCrossAction();
if (accountStreams != null) {
for (final Account accountStream : accountStreams) {
if( accountStream.getSocial() == null || accountStream.getSocial().equals("MASTODON")) {

View File

@ -206,6 +206,34 @@ public class AccountDAO {
}
}
/**
* Returns all Account in db
* @return Account List<Account>
*/
public List<Account> getAllAccountActivated(){
try {
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_OAUTHTOKEN + " != 'null'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
return cursorToListUser(c);
} catch (Exception e) {
return null;
}
}
/**
* Returns all Account in db
* @return Account List<Account>
*/
public List<Account> getAllAccountCrossAction(){
try {
Cursor c = db.query(Sqlite.TABLE_USER_ACCOUNT, null, Sqlite.COL_SOCIAL + " != 'PEERTUBE AND " + Sqlite.COL_OAUTHTOKEN + " != 'null'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
return cursorToListUser(c);
} catch (Exception e) {
return null;
}
}
/**
* Returns an Account by token