Skip to content

Commit

Permalink
refactorings for better performance and stable switching between main…
Browse files Browse the repository at this point in the history
… and detail with selected notebook. work is not finished yet
  • Loading branch information
konradrenner committed Jun 29, 2015
1 parent ed6a062 commit d0b6d31
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/kore/kolabnotes/android/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Utils {
public static final String INTENT_ACCOUNT_ROOT_FOLDER = "intent_account_rootfolder";
public static final String NOTE_UID = "note_uid";
public static final String NOTEBOOK_UID = "notebook_uid";

public static final String SELECTED_NOTEBOOK_NAME = "selectedNotebookName";
/*
public static void configureWindowEnterExitTransition(Window w) {
Explode ex = new Explode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void onBindViewHolder(final ViewHolder viewHolder, int i) {
}else{
viewHolder.cardView.setCardBackgroundColor(Color.WHITE);
}
viewHolder.cardView.setElevation(5);


viewHolder.itemView.setOnClickListener(new ClickListener(i));
Expand All @@ -102,7 +103,7 @@ public void onClick(View v) {
if(parent instanceof RecyclerView){
RecyclerView recyclerView = (RecyclerView)parent;
for(int i=0; i < recyclerView.getChildCount(); i++){
recyclerView.getChildAt(i).setElevation(0);
recyclerView.getChildAt(i).setElevation(5);
}
}
v.setElevation(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -561,8 +563,12 @@ void saveNote(){
}

Intent returnIntent = new Intent();
if (isNewNote || givenNotebook != null) {
returnIntent.putExtra("selectedNotebookName", notebookName);
if (isNewNote) {
SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
sharedPref.edit().putString(Utils.SELECTED_NOTEBOOK_NAME,notebookName);
if(givenNotebook !=null){
returnIntent.putExtra("selectedNotebookName", notebookName);
}
}
Utils.updateWidgetsForChange(activity.getApplication());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
Expand Down Expand Up @@ -97,6 +99,8 @@ public class OverviewFragment extends Fragment implements NoteAdapter.NoteSelect
private AccountHeader mAccount;
private boolean tabletMode;

private boolean initPhase;

private MainActivity activity;

@Override
Expand Down Expand Up @@ -129,6 +133,7 @@ public void onAttach(Activity activity) {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

initPhase = true;
// Handle Toolbar
toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
activity.setSupportActionBar(toolbar);
Expand Down Expand Up @@ -179,7 +184,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
Utils.configureFab(mFabButton);
mFabButton.setOnClickListener(new CreateButtonListener());

mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.list);
mRecyclerView = (RecyclerView) activity.findViewById(R.id.list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
//mRecyclerView.setItemAnimator(new CustomItemAnimator());
//mRecyclerView.setItemAnimator(new ReboundItemAnimator());
Expand Down Expand Up @@ -367,7 +372,10 @@ public void onResume(){
Intent startIntent = getActivity().getIntent();
String email = startIntent.getStringExtra(Utils.INTENT_ACCOUNT_EMAIL);
String rootFolder = startIntent.getStringExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER);
String notebookUID = startIntent.getStringExtra(Utils.NOTEBOOK_UID);
//String notebookUID = startIntent.getStringExtra(Utils.NOTEBOOK_UID);

SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
selectedNotebookName = sharedPref.getString(Utils.SELECTED_NOTEBOOK_NAME,null);

ActiveAccount activeAccount;
if(email != null && rootFolder != null) {
Expand All @@ -376,9 +384,6 @@ public void onResume(){
activeAccount = activeAccountRepository.getActiveAccount();
}

if(notebookUID != null){
selectedNotebookName = notebookRepository.getByUID(activeAccount.getAccount(),activeAccount.getRootFolder(),notebookUID).getSummary();
}

AccountHeader accountHeader = mAccount;
for(IProfile profile : accountHeader.getProfiles()){
Expand All @@ -392,7 +397,12 @@ public void onResume(){
}
}

if(initPhase){
initPhase = false;
return;
}

String notebookUID = null;
if(fromDetailActivity || tabletMode){
if(selectedNotebookName != null) {
Notebook nb = notebookRepository.getBySummary(activeAccount.getAccount(), activeAccount.getRootFolder(), selectedNotebookName);
Expand Down Expand Up @@ -637,19 +647,25 @@ public void changeNoteSelection(BaseDrawerItem drawerItem){
String tag = drawerItem.getTag() == null || drawerItem.getTag().toString().trim().length() == 0 ? "ALL_NOTEBOOK" : drawerItem.getTag().toString();
List<Note> notes;
ActiveAccount activeAccount = activeAccountRepository.getActiveAccount();
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
if("NOTEBOOK".equalsIgnoreCase(tag)){
Notebook notebook = notebookRepository.getBySummary(activeAccount.getAccount(), activeAccount.getRootFolder(), drawerItem.getName());
notes = notesRepository.getFromNotebook(activeAccount.getAccount(),activeAccount.getRootFolder(),notebook.getIdentification().getUid());
selectedNotebookName = notebook.getSummary();

sharedPref.edit().putString(Utils.SELECTED_NOTEBOOK_NAME,selectedNotebookName);
}else if("TAG".equalsIgnoreCase(tag)){
notes = notetagRepository.getNotesWith(activeAccount.getAccount(), activeAccount.getRootFolder(), drawerItem.getName());
selectedNotebookName = null;
sharedPref.edit().remove(Utils.SELECTED_NOTEBOOK_NAME);
}else if("ALL_NOTES".equalsIgnoreCase(tag)){
notes = notesRepository.getAll();
selectedNotebookName = null;
sharedPref.edit().remove(Utils.SELECTED_NOTEBOOK_NAME);
}else{
notes = notesRepository.getAll(activeAccount.getAccount(),activeAccount.getRootFolder());
selectedNotebookName = null;
sharedPref.edit().remove(Utils.SELECTED_NOTEBOOK_NAME);
}

if(mAdapter != null) {
Expand Down Expand Up @@ -870,6 +886,9 @@ public void onClick(DialogInterface dialog, int which) {
String value = textField.getText().toString();
selectedNotebookName = value;

SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE);
sharedPref.edit().putString(Utils.SELECTED_NOTEBOOK_NAME,selectedNotebookName);

Notebook nb = new Notebook(ident,audit, Note.Classification.PUBLIC, value);
nb.setDescription(value);
if(notebookRepository.insert(activeAccount.getAccount(), activeAccount.getRootFolder(), nb)) {
Expand Down

0 comments on commit d0b6d31

Please sign in to comment.