Version 37 reconstructed

This commit is contained in:
Caesar2011
2019-02-15 17:56:29 +01:00
parent e31d6cd042
commit 8655dc9927
4 changed files with 62 additions and 33 deletions

View File

@@ -9,6 +9,7 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -26,6 +27,7 @@ import java.util.Iterator;
import java.util.Locale;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.arch.core.util.Function;
import androidx.appcompat.app.ActionBarDrawerToggle;
@@ -52,6 +54,7 @@ import de.sebse.fuplanner.services.kvv.KVV;
import de.sebse.fuplanner.services.kvv.KVVListener;
import de.sebse.fuplanner.services.kvv.Login;
import de.sebse.fuplanner.services.kvv.sync.KVVContentProvider;
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
import de.sebse.fuplanner.services.kvv.types.LoginTokenKVV;
import de.sebse.fuplanner.services.kvv.types.Modules;
import de.sebse.fuplanner.services.news.NewsManager;
@@ -91,9 +94,11 @@ public class MainActivity extends AppCompatActivity
private final Logger log = new Logger(this);
private NavigationView mNavigationView;
private boolean mAlreadyCreated = false;
// KVV service
private ArrayList<KVVCallback> mCallbacks = new ArrayList<>();
private KVV mKVV;
@Nullable private KVV mKVV;
boolean mBound = false;
/** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
@@ -115,6 +120,7 @@ public class MainActivity extends AppCompatActivity
public void onServiceDisconnected(ComponentName arg0) {
mKVV.removeListener("mainactivity");
mBound = false;
mKVV = null;
}
};
@@ -140,14 +146,12 @@ public class MainActivity extends AppCompatActivity
int desiredPage = getDefaultFragmentAfterLogin();
String desiredData = "";
Intent intent = getIntent();
if (intent != null) {
if (CustomNotificationManager.NOTIFICATION_TYPE_NAVIGATE.equals(intent.getStringExtra(CustomNotificationManager.NOTIFICATION_INTENT))) {
int page = intent.getIntExtra(CustomNotificationManager.NOTIFICATION_PAGE, 0);
if (page == FRAGMENT_STARTUP || page == FRAGMENT_NONE)
page = getDefaultFragmentAfterLogin();
desiredPage = page;
desiredData = intent.getStringExtra(CustomNotificationManager.NOTIFICATION_DATA);
}
if (intent != null && CustomNotificationManager.NOTIFICATION_TYPE_NAVIGATE.equals(intent.getStringExtra(CustomNotificationManager.NOTIFICATION_INTENT))) {
int page = intent.getIntExtra(CustomNotificationManager.NOTIFICATION_PAGE, 0);
if (page == FRAGMENT_STARTUP || page == FRAGMENT_NONE)
page = getDefaultFragmentAfterLogin();
desiredPage = page;
desiredData = intent.getStringExtra(CustomNotificationManager.NOTIFICATION_DATA);
} else if (savedInstanceState != null) {
desiredPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, desiredPage);
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
@@ -173,7 +177,7 @@ public class MainActivity extends AppCompatActivity
if (!mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
desiredPage = getDefaultFragmentAfterLogout();
desiredData = "";
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null, null);
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
updateNavigation();
changeFragment(desiredPage, desiredData);
} else {
@@ -192,6 +196,12 @@ public class MainActivity extends AppCompatActivity
});
}
if (!mAlreadyCreated) {
Intent serviceIntent = new Intent(this, KVV.class);
bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
}
mAlreadyCreated = true;
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
registerSync(true);
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
@@ -199,25 +209,34 @@ public class MainActivity extends AppCompatActivity
registerSync(false);
}
CustomNotificationManager.createNotificationChannel(this);
/*getKVV().modules().list().recv(list -> {
Modules.Module module = list.getByIndex(0);
CustomNotificationManager.sendNotification(this, "Test", module.title, FRAGMENT_MODULES_DETAILS, module.getID()+"."+ModulePart.getPageByPart(ModulePart.EVENT));
}, log::e);*/
/*getKVV(kvv -> {
kvv.modules().list().recv(list -> {
Modules.Module module = list.getByIndex(0);
CustomNotificationManager.sendNotification(this, "Test", module.title, FRAGMENT_MODULES_DETAILS, module.getID()+"."+ ModulePart.getPageByPart(ModulePart.EVENT));
}, log::e);
});*/
}
@Override
protected void onStart() {
super.onStart();
Intent intent = new Intent(this, KVV.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
if (!mAlreadyCreated) {
Intent serviceIntent = new Intent(this, KVV.class);
bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
}
mAlreadyCreated = true;
}
@Override
protected void onStop() {
super.onStop();
mKVV.removeListener("mainactivity");
unbindService(mConnection);
if (mKVV != null)
mKVV.removeListener("mainactivity");
if (mBound)
unbindService(mConnection);
mKVV = null;
mBound = false;
mAlreadyCreated = false;
}
@Override
@@ -291,7 +310,7 @@ public class MainActivity extends AppCompatActivity
} else {
mDoubleBackToExitPressedOnce = System.currentTimeMillis();
showToast(R.string.back_to_exit);
//getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV);
//getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD);
}
});
}
@@ -442,7 +461,7 @@ public class MainActivity extends AppCompatActivity
setRefreshFailedBanner(false);
updateNavigation();
changeFragment(getDefaultFragmentAfterLogout());
//mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null, null);
//mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
}
private void toLoginState(String fullName, String email, int newFragment) {
@@ -615,7 +634,7 @@ public class MainActivity extends AppCompatActivity
if (drawer.isDrawerOpen(GravityCompat.START) && !isDrawerFixed) {
drawer.closeDrawer(GravityCompat.START);
}
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null, null);
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
});
}
@@ -770,8 +789,21 @@ public class MainActivity extends AppCompatActivity
@Override
public void onLogin(LoginTokenKVV token, boolean isOnlyRefresh) {
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin());
public void onLogin(LoginTokenKVV tokenKVV, LoginTokenBB tokenBB, boolean isOnlyRefresh) {
String fullName = "";
if (tokenKVV != null && !TextUtils.isEmpty(tokenKVV.getFullName())) {
fullName = tokenKVV.getFullName();
} else if (tokenBB != null && !TextUtils.isEmpty(tokenBB.getUsername())) {
fullName = tokenBB.getUsername();
}
String email = "";
if (tokenKVV != null && !TextUtils.isEmpty(tokenKVV.getEmail())) {
email = tokenKVV.getFullName();
} else if (tokenBB != null && !TextUtils.isEmpty(tokenBB.getUsername())) {
email = tokenBB.getUsername() + "@zedat.fu-berlin.de";
}
toLoginState(fullName, email, getDefaultFragmentAfterLogin());
}
@Override

View File

@@ -12,9 +12,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
import de.sebse.fuplanner.services.kvv.types.LoginTokenKVV;
import de.sebse.fuplanner.tools.CustomAccountManager;
import de.sebse.fuplanner.tools.logging.Logger;
public class KVV extends Service {
private final HashMap<String, Object> addons = new HashMap<>();
@@ -36,9 +36,9 @@ public class KVV extends Service {
}
@Override
public void onLogin(LoginTokenKVV token, boolean isOnlyRefresh) {
public void onLogin(LoginTokenKVV tokenKVV, LoginTokenBB tokenBB, boolean isOnlyRefresh) {
for (KVVListener listener : mListeners.values())
listener.onLogin(token, isOnlyRefresh);
listener.onLogin(tokenKVV, tokenBB, isOnlyRefresh);
}
@Override
@@ -60,10 +60,6 @@ public class KVV extends Service {
}
};
public KVV() {
Logger log = new Logger(this);
}
// Binder given to clients
private final IBinder mBinder = new LocalBinder();

View File

@@ -2,12 +2,13 @@ package de.sebse.fuplanner.services.kvv;
import com.android.volley.NetworkResponse;
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
import de.sebse.fuplanner.services.kvv.types.LoginTokenKVV;
import de.sebse.fuplanner.services.kvv.types.Modules;
import de.sebse.fuplanner.tools.CustomAccountManager;
public interface KVVListener {
default void onLogin(LoginTokenKVV token, boolean isOnlyRefresh) {}
default void onLogin(LoginTokenKVV tokenKVV, LoginTokenBB tokenBB, boolean isOnlyRefresh) {}
default void onLogout() {}

View File

@@ -164,8 +164,8 @@ public class Login extends HTTPService {
private boolean handleCallbacks(boolean isOnlyRefresh) {
if (mTokenKVV != null) {
mListener.onLogin(mTokenKVV, isOnlyRefresh);
if (mTokenKVV != null || mTokenBB != null) {
mListener.onLogin(mTokenKVV, mTokenBB, isOnlyRefresh);
return true;
} else {
mListener.onLogout();