Check for nulls when creating

This commit is contained in:
stefan-niedermann 2019-10-04 13:12:54 +02:00
parent a4a71432ea
commit 475358bb6c
3 changed files with 42 additions and 42 deletions

View file

@ -171,7 +171,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
try {
localAccount = db.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(getApplicationContext()).name);
Log.v("Notes", "current sso account " + localAccount.getAccountName());
Log.v("Notes", "NextcloudRequest account: " + localAccount);
} catch (NextcloudFilesAppAccountNotFoundException e) {
e.printStackTrace();
} catch (NoCurrentAccountSelectedException e) {
@ -195,33 +195,36 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
setContentView(R.layout.drawer_layout);
ButterKnife.bind(this);
String categoryAdapterSelectedItem = ADAPTER_KEY_RECENT;
if (savedInstanceState == null) {
if (ACTION_RECENT.equals(getIntent().getAction())) {
categoryAdapterSelectedItem = ADAPTER_KEY_RECENT;
} else if (ACTION_FAVORITES.equals(getIntent().getAction())) {
categoryAdapterSelectedItem = ADAPTER_KEY_STARRED;
navigationSelection = new Category(null, true);
if(localAccount != null) {
String categoryAdapterSelectedItem = ADAPTER_KEY_RECENT;
if (savedInstanceState == null) {
if (ACTION_RECENT.equals(getIntent().getAction())) {
categoryAdapterSelectedItem = ADAPTER_KEY_RECENT;
} else if (ACTION_FAVORITES.equals(getIntent().getAction())) {
categoryAdapterSelectedItem = ADAPTER_KEY_STARRED;
navigationSelection = new Category(null, true);
}
} else {
navigationSelection = (Category) savedInstanceState.getSerializable(SAVED_STATE_NAVIGATION_SELECTION);
navigationOpen = savedInstanceState.getString(SAVED_STATE_NAVIGATION_OPEN);
categoryAdapterSelectedItem = savedInstanceState.getString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION);
}
} else {
navigationSelection = (Category) savedInstanceState.getSerializable(SAVED_STATE_NAVIGATION_SELECTION);
navigationOpen = savedInstanceState.getString(SAVED_STATE_NAVIGATION_OPEN);
categoryAdapterSelectedItem = savedInstanceState.getString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION);
setupActionBar();
setupNotesList();
setupNavigationList(categoryAdapterSelectedItem);
setupNavigationMenu();
}
setupActionBar();
setupNotesList();
setupNavigationList(categoryAdapterSelectedItem);
setupNavigationMenu();
}
@Override
protected void onResume() {
// refresh and sync every time the activity gets visible
refreshLists();
db.getNoteServerSyncHelper().addCallbackPull(syncCallBack);
if (db.getNoteServerSyncHelper().isSyncPossible()) {
synchronize();
// refresh and sync every time the activity gets
if(localAccount != null) {
refreshLists();
db.getNoteServerSyncHelper().addCallbackPull(syncCallBack);
if (db.getNoteServerSyncHelper().isSyncPossible()) {
synchronize();
}
}
super.onResume();
}
@ -229,21 +232,27 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
if(localAccount != null) {
drawerToggle.syncState();
}
}
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.syncState();
if(localAccount != null) {
drawerToggle.syncState();
}
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(SAVED_STATE_NAVIGATION_SELECTION, navigationSelection);
outState.putString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION, adapterCategories.getSelectedItem());
outState.putString(SAVED_STATE_NAVIGATION_OPEN, navigationOpen);
if(localAccount != null) {
outState.putSerializable(SAVED_STATE_NAVIGATION_SELECTION, navigationSelection);
outState.putString(SAVED_STATE_NAVIGATION_ADAPTER_SLECTION, adapterCategories.getSelectedItem());
outState.putString(SAVED_STATE_NAVIGATION_OPEN, navigationOpen);
}
}
private void setupActionBar() {

View file

@ -18,7 +18,6 @@ import com.nextcloud.android.sso.helper.SingleAccountHelper;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -102,6 +101,7 @@ public class NoteServerSyncHelper {
this.appContext = db.getContext().getApplicationContext();
try {
this.localAccount = db.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(appContext).name);
Log.v("Notes", "NextcloudRequest account: " + localAccount);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
}
@ -347,7 +347,6 @@ public class NoteServerSyncHelper {
dbHelper.deleteNote(entry.getValue(), DBStatus.VOID);
}
}
status = LoginStatus.OK;
// update ETag and Last-Modified in order to reduce size of next response
SharedPreferences.Editor editor = preferences.edit();
@ -364,13 +363,7 @@ public class NoteServerSyncHelper {
editor.remove(AccountActivity.SETTINGS_KEY_LAST_MODIFIED);
}
editor.apply();
} catch (ServerResponse.NotModifiedException e) {
Log.d(getClass().getSimpleName(), "No changes, nothing to do.");
status = LoginStatus.OK;
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Exception", e);
exceptions.add(e);
status = LoginStatus.CONNECTION_FAILED;
return LoginStatus.OK;
} catch (JSONException e) {
Log.e(getClass().getSimpleName(), "Exception", e);
exceptions.add(e);

View file

@ -17,7 +17,6 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
@ -77,6 +76,7 @@ public class NotesClient {
public NotesClient(Context context) {
try {
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
Log.v("Notes", "NextcloudRequest account: " + ssoAccount.name);
mNextcloudAPI = new NextcloudAPI(context, ssoAccount, new GsonBuilder().create(), new NextcloudAPI.ApiConnectedListener() {
@Override
public void onConnected() {
@ -88,14 +88,12 @@ public class NotesClient {
ex.printStackTrace();
}
});
} catch (NextcloudFilesAppAccountNotFoundException e) {
// TODO handle errors
} catch (NoCurrentAccountSelectedException e) {
// TODO handle errors
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
}
}
public NotesResponse getNotes(long lastModified, String lastETag) throws JSONException, IOException {
public NotesResponse getNotes(long lastModified, String lastETag) {
String url = "notes";
if (lastModified > 0) {
url += "?pruneBefore=" + lastModified;