|
@@ -26,6 +26,7 @@ import androidx.appcompat.app.ActionBar;
|
|
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
|
+import androidx.core.app.ActivityCompat;
|
|
|
import androidx.core.view.GravityCompat;
|
|
import androidx.core.view.GravityCompat;
|
|
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
@@ -86,6 +87,8 @@ public class MainActivity extends BaseActivity
|
|
|
|
|
|
|
|
private static final int CHANGE_LANGUAGE_DELAY = 1000;
|
|
private static final int CHANGE_LANGUAGE_DELAY = 1000;
|
|
|
private static boolean firstTime = true;//true only when app starting
|
|
private static boolean firstTime = true;//true only when app starting
|
|
|
|
|
+ private static final int LOGIN_REQUEST_CODE = 1;
|
|
|
|
|
+
|
|
|
private final InspectorV3.InspectorResponse startGallery = new MainInspectorResponse() {
|
|
private final InspectorV3.InspectorResponse startGallery = new MainInspectorResponse() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onSuccess(List<GenericGallery> galleries) {
|
|
public void onSuccess(List<GenericGallery> galleries) {
|
|
@@ -197,31 +200,6 @@ public class MainActivity extends BaseActivity
|
|
|
.centerCrop()
|
|
.centerCrop()
|
|
|
.placeholder(R.drawable.ic_logo)
|
|
.placeholder(R.drawable.ic_logo)
|
|
|
.into(ivAd);
|
|
.into(ivAd);
|
|
|
-
|
|
|
|
|
- HttpClient.request(HttpClient.getApiService().register(new UserRegister("asdf1", "123456", null)), new HttpCallback<NUser>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onSuccess(NUser data) {
|
|
|
|
|
- LogUtility.d("Register success");
|
|
|
|
|
- HttpClient.request(HttpClient.getApiService().login(new UserLogin("asdf1", "123456")), new HttpCallback<LoginResponse>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onSuccess(LoginResponse data) {
|
|
|
|
|
- LogUtility.d("Login success");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onFailure(HttpError<LoginResponse> error) {
|
|
|
|
|
- LogUtility.e("Login failed");
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onFailure(HttpError<NUser> error) {
|
|
|
|
|
- LogUtility.e("Register failed");
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void manageDrawer() {
|
|
private void manageDrawer() {
|
|
@@ -311,6 +289,7 @@ public class MainActivity extends BaseActivity
|
|
|
toolbar.setNavigationOnClickListener(v -> finish());
|
|
toolbar.setNavigationOnClickListener(v -> finish());
|
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
navigationView.setNavigationItemSelectedListener(this);
|
|
|
onlineFavoriteManager.setVisible(com.dar.nbook.settings.Login.isLogged());
|
|
onlineFavoriteManager.setVisible(com.dar.nbook.settings.Login.isLogged());
|
|
|
|
|
+ com.dar.nbook.settings.Login.isNLogged(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void setIdOpenedGallery(int idOpenedGallery) {
|
|
public void setIdOpenedGallery(int idOpenedGallery) {
|
|
@@ -331,10 +310,10 @@ public class MainActivity extends BaseActivity
|
|
|
|
|
|
|
|
private void loadStringLogin() {
|
|
private void loadStringLogin() {
|
|
|
if (loginItem == null) return;
|
|
if (loginItem == null) return;
|
|
|
- if (com.dar.nbook.settings.Login.getUser() != null)
|
|
|
|
|
- loginItem.setTitle(getString(R.string.login_formatted, com.dar.nbook.settings.Login.getUser().getUsername()));
|
|
|
|
|
|
|
+ if (com.dar.nbook.settings.Login.getNUser() != null)
|
|
|
|
|
+ loginItem.setTitle(getString(R.string.login_formatted, com.dar.nbook.settings.Login.getNUser().getUsername()));
|
|
|
else
|
|
else
|
|
|
- loginItem.setTitle(com.dar.nbook.settings.Login.isLogged() ? R.string.logout : R.string.login);
|
|
|
|
|
|
|
+ loginItem.setTitle(com.dar.nbook.settings.Login.isNLogged(this) ? R.string.logout : R.string.login);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -802,11 +781,11 @@ public class MainActivity extends BaseActivity
|
|
|
intent.putExtra(getPackageName() + ".FAVORITE", true);
|
|
intent.putExtra(getPackageName() + ".FAVORITE", true);
|
|
|
startActivity(intent);
|
|
startActivity(intent);
|
|
|
} else if (item.getItemId() == R.id.action_login) {
|
|
} else if (item.getItemId() == R.id.action_login) {
|
|
|
- if (Login.isLogged())
|
|
|
|
|
|
|
+ if (Login.isNLogged(this))
|
|
|
showLogoutForm();
|
|
showLogoutForm();
|
|
|
else {
|
|
else {
|
|
|
intent = new Intent(this, BLoginActivity.class);
|
|
intent = new Intent(this, BLoginActivity.class);
|
|
|
- startActivity(intent);
|
|
|
|
|
|
|
+ ActivityCompat.startActivityForResult(this, intent, LOGIN_REQUEST_CODE, null);
|
|
|
}
|
|
}
|
|
|
} else if (item.getItemId() == R.id.random) {
|
|
} else if (item.getItemId() == R.id.random) {
|
|
|
intent = new Intent(this, RandomActivity.class);
|
|
intent = new Intent(this, RandomActivity.class);
|
|
@@ -901,4 +880,13 @@ public class MainActivity extends BaseActivity
|
|
|
this.locale = Global.initLanguage(MainActivity.this);
|
|
this.locale = Global.initLanguage(MainActivity.this);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
|
|
|
|
+ super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
+ if (requestCode == LOGIN_REQUEST_CODE && resultCode == RESULT_OK) {
|
|
|
|
|
+ drawerLayout.close();
|
|
|
|
|
+ snackbar = showSuccess(R.string.login_success);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|