Дописываю приложение, коснулся вопрос повторяемости кода и оптимизации.
В приложении есть около 20 активити в каждой из которых одинаковый метод, который меняет видимость пунктов экшн бара в зависимости от сохраненной переменной.
Код: Выделить всё
private void checkAuth() {
if (mOutAuth == null || mAuth == null) {
return;
}
//Get Authoriization state
boolean checkFlagAuth = Utility.loadCheckAuth(this);
boolean checkAuth = Utility.isAuth(this);
//for auth user change menu
if (checkAuth || checkFlagAuth) {
mAuth.setVisible(false);
mOutAuth.setTitle(Utility.getLogin(this));
} else {
mOutAuth.setVisible(false);
}
}
Код: Выделить всё
public static void checkAuth(Context context, MenuItem mOuthAuth, MenuItem mAuth) {
if (mOutAuth == null || mAuth == null) {
return;
}
//Get Authoriization state
boolean checkFlagAuth = Utility.loadCheckAuth(this);
boolean checkAuth = Utility.isAuth(this);
//for auth user change menu
if (checkAuth || checkFlagAuth) {
mAuth.setVisible(false);
mOutAuth.setTitle(Utility.getLogin(this));
} else {
mOutAuth.setVisible(false);
}
}