diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ca914bc3f..527951521 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,9 +11,9 @@ android:fullBackupContent="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:supportsRtl="true" android:networkSecurityConfig="@xml/network_security_config" - android:theme="@style/OwnCloud"> + android:supportsRtl="true" + android:theme="@style/Nextcloud"> (this, R.layout.fragment_drawer_item, new String[]{ + "Alle Notizen", + "Favoriten" + })); + final DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (SDK_INT >= 14) { + mDrawerLayout.closeDrawer(Gravity.START); + } else { + mDrawerLayout.closeDrawer(Gravity.LEFT); + } + } + }); + mDrawerLayout.addDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, + R.string.drawer_opened, R.string.drawer_closed) { + public void onDrawerClosed(View view) { + super.onDrawerClosed(view); + getSupportActionBar().setTitle(mTitle); + invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() + } + + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + getSupportActionBar().setTitle(mDrawerTitle); + invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() + } + }); + + mTitle = mDrawerTitle = getTitle(); } - protected void checkNotificationSetting(){ + protected void checkNotificationSetting() { SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); Boolean showNotification = preferences.getBoolean("showNotification", false); - if(showNotification==true){ + if (showNotification == true) { // add notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this); PendingIntent newNoteIntent = PendingIntent.getActivity(this, 0, @@ -130,8 +177,7 @@ protected void checkNotificationSetting(){ NOTIFICATION_SERVICE); notificationManager.notify(10, builder.build()); - } - else{ + } else { // remove notification NotificationManager nMgr = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE); nMgr.cancel(10); @@ -173,102 +219,6 @@ public void refreshList() { new RefreshListTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - private class RefreshListTask extends AsyncTask> { - - private CharSequence query = null; - - @Override - protected void onPreExecute() { - if(searchView != null && !searchView.isIconified() && searchView.getQuery().length() != 0) { - query = searchView.getQuery(); - } - } - - @Override - protected List doInBackground(Void... voids) { - List noteList; - if (query==null) { - noteList = db.getNotes(); - } else { - noteList = db.searchNotes(query); - } - - final List itemList = new ArrayList<>(); - // #12 Create Sections depending on Time - // TODO Move to ItemAdapter? - boolean todaySet, yesterdaySet, weekSet, monthSet, earlierSet; - todaySet = yesterdaySet = weekSet = monthSet = earlierSet = false; - Calendar recent = Calendar.getInstance(); - Calendar today = Calendar.getInstance(); - today.set(Calendar.HOUR_OF_DAY, 0); - today.set(Calendar.MINUTE, 0); - today.set(Calendar.SECOND, 0); - today.set(Calendar.MILLISECOND, 0); - Calendar yesterday = Calendar.getInstance(); - yesterday.set(Calendar.DAY_OF_YEAR, yesterday.get(Calendar.DAY_OF_YEAR) - 1); - yesterday.set(Calendar.HOUR_OF_DAY, 0); - yesterday.set(Calendar.MINUTE, 0); - yesterday.set(Calendar.SECOND, 0); - yesterday.set(Calendar.MILLISECOND, 0); - Calendar week = Calendar.getInstance(); - week.set(Calendar.DAY_OF_WEEK, week.getFirstDayOfWeek()); - week.set(Calendar.HOUR_OF_DAY, 0); - week.set(Calendar.MINUTE, 0); - week.set(Calendar.SECOND, 0); - week.set(Calendar.MILLISECOND, 0); - Calendar month = Calendar.getInstance(); - month.set(Calendar.DAY_OF_MONTH, 0); - month.set(Calendar.HOUR_OF_DAY, 0); - month.set(Calendar.MINUTE, 0); - month.set(Calendar.SECOND, 0); - month.set(Calendar.MILLISECOND, 0); - for (int i = 0; i < noteList.size(); i++) { - DBNote currentNote = noteList.get(i); - if (currentNote.isFavorite()) { - // don't show as new section - } else if (!todaySet && currentNote.getModified().getTimeInMillis() >= today.getTimeInMillis()) { - // after 00:00 today - if (i > 0) { - itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_today))); - } - todaySet = true; - } else if (!yesterdaySet && currentNote.getModified().getTimeInMillis() < today.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= yesterday.getTimeInMillis()) { - // between today 00:00 and yesterday 00:00 - if (i > 0) { - itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_yesterday))); - } - yesterdaySet = true; - } else if (!weekSet && currentNote.getModified().getTimeInMillis() < yesterday.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= week.getTimeInMillis()) { - // between yesterday 00:00 and start of the week 00:00 - if (i > 0) { - itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_this_week))); - } - weekSet = true; - } else if (!monthSet && currentNote.getModified().getTimeInMillis() < week.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= month.getTimeInMillis()) { - // between start of the week 00:00 and start of the month 00:00 - if (i > 0) { - itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_this_month))); - } - monthSet = true; - } else if (!earlierSet && currentNote.getModified().getTimeInMillis() < month.getTimeInMillis()) { - // before start of the month 00:00 - if (i > 0) { - itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_earlier))); - } - earlierSet = true; - } - itemList.add(currentNote); - } - - return itemList; - } - - @Override - protected void onPostExecute(List items) { - adapter.setItemList(items); - } - } - public void initList() { adapter = new ItemAdapter(this); listView = (RecyclerView) findViewById(R.id.recycler_view); @@ -325,7 +275,7 @@ public void onClick(View v) { public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { ItemAdapter.NoteViewHolder noteViewHolder = (ItemAdapter.NoteViewHolder) viewHolder; // show delete icon on the right side - noteViewHolder.showSwipeDelete(dX>0); + noteViewHolder.showSwipeDelete(dX > 0); // move only swipeable part of item (not leave-behind) getDefaultUIUtil().onDraw(c, recyclerView, noteViewHolder.noteSwipeable, dX, dY, actionState, isCurrentlyActive); } @@ -418,7 +368,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } else if (requestCode == show_single_note_cmd) { if (resultCode == RESULT_OK || resultCode == RESULT_FIRST_USER) { int notePosition = data.getExtras().getInt(EditNoteActivity.PARAM_NOTE_POSITION); - if(adapter.getItemCount()>notePosition) { + if (adapter.getItemCount() > notePosition) { Item oldItem = adapter.getItem(notePosition); if (resultCode == RESULT_FIRST_USER) { adapter.remove(oldItem); @@ -433,7 +383,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { } else if (requestCode == server_settings) { // Create new Instance with new URL and credentials db = NoteSQLiteOpenHelper.getInstance(this); - if(db.getNoteServerSyncHelper().isSyncPossible()) { + if (db.getNoteServerSyncHelper().isSyncPossible()) { adapter.removeAll(); swipeRefreshLayout.setRefreshing(true); synchronize(); @@ -503,7 +453,7 @@ public boolean onNoteLongClick(int position, View v) { @Override public void onBackPressed() { - if (searchView==null || searchView.isIconified()) { + if (searchView == null || searchView.isIconified()) { super.onBackPressed(); } else { searchView.setIconified(true); @@ -515,6 +465,102 @@ private void synchronize() { db.getNoteServerSyncHelper().scheduleSync(false); } + private class RefreshListTask extends AsyncTask> { + + private CharSequence query = null; + + @Override + protected void onPreExecute() { + if (searchView != null && !searchView.isIconified() && searchView.getQuery().length() != 0) { + query = searchView.getQuery(); + } + } + + @Override + protected List doInBackground(Void... voids) { + List noteList; + if (query == null) { + noteList = db.getNotes(); + } else { + noteList = db.searchNotes(query); + } + + final List itemList = new ArrayList<>(); + // #12 Create Sections depending on Time + // TODO Move to ItemAdapter? + boolean todaySet, yesterdaySet, weekSet, monthSet, earlierSet; + todaySet = yesterdaySet = weekSet = monthSet = earlierSet = false; + Calendar recent = Calendar.getInstance(); + Calendar today = Calendar.getInstance(); + today.set(Calendar.HOUR_OF_DAY, 0); + today.set(Calendar.MINUTE, 0); + today.set(Calendar.SECOND, 0); + today.set(Calendar.MILLISECOND, 0); + Calendar yesterday = Calendar.getInstance(); + yesterday.set(Calendar.DAY_OF_YEAR, yesterday.get(Calendar.DAY_OF_YEAR) - 1); + yesterday.set(Calendar.HOUR_OF_DAY, 0); + yesterday.set(Calendar.MINUTE, 0); + yesterday.set(Calendar.SECOND, 0); + yesterday.set(Calendar.MILLISECOND, 0); + Calendar week = Calendar.getInstance(); + week.set(Calendar.DAY_OF_WEEK, week.getFirstDayOfWeek()); + week.set(Calendar.HOUR_OF_DAY, 0); + week.set(Calendar.MINUTE, 0); + week.set(Calendar.SECOND, 0); + week.set(Calendar.MILLISECOND, 0); + Calendar month = Calendar.getInstance(); + month.set(Calendar.DAY_OF_MONTH, 0); + month.set(Calendar.HOUR_OF_DAY, 0); + month.set(Calendar.MINUTE, 0); + month.set(Calendar.SECOND, 0); + month.set(Calendar.MILLISECOND, 0); + for (int i = 0; i < noteList.size(); i++) { + DBNote currentNote = noteList.get(i); + if (currentNote.isFavorite()) { + // don't show as new section + } else if (!todaySet && currentNote.getModified().getTimeInMillis() >= today.getTimeInMillis()) { + // after 00:00 today + if (i > 0) { + itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_today))); + } + todaySet = true; + } else if (!yesterdaySet && currentNote.getModified().getTimeInMillis() < today.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= yesterday.getTimeInMillis()) { + // between today 00:00 and yesterday 00:00 + if (i > 0) { + itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_yesterday))); + } + yesterdaySet = true; + } else if (!weekSet && currentNote.getModified().getTimeInMillis() < yesterday.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= week.getTimeInMillis()) { + // between yesterday 00:00 and start of the week 00:00 + if (i > 0) { + itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_this_week))); + } + weekSet = true; + } else if (!monthSet && currentNote.getModified().getTimeInMillis() < week.getTimeInMillis() && currentNote.getModified().getTimeInMillis() >= month.getTimeInMillis()) { + // between start of the week 00:00 and start of the month 00:00 + if (i > 0) { + itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_this_month))); + } + monthSet = true; + } else if (!earlierSet && currentNote.getModified().getTimeInMillis() < month.getTimeInMillis()) { + // before start of the month 00:00 + if (i > 0) { + itemList.add(new SectionItem(getResources().getString(R.string.listview_updated_earlier))); + } + earlierSet = true; + } + itemList.add(currentNote); + } + + return itemList; + } + + @Override + protected void onPostExecute(List items) { + adapter.setItemList(items); + } + } + /** * Handler for the MultiSelect Actions */ diff --git a/app/src/main/res/layout/activity_notes_list_view.xml b/app/src/main/res/layout/activity_notes_list_view.xml index 61d9873b1..34ad329e8 100644 --- a/app/src/main/res/layout/activity_notes_list_view.xml +++ b/app/src/main/res/layout/activity_notes_list_view.xml @@ -1,30 +1,53 @@ - - + + android:layout_height="match_parent"> - - - - - - \ No newline at end of file + android:layout_height="match_parent" + android:background="@color/bg_normal" + tools:context="it.niedermann.owncloud.notes.android.activity.NotesListViewActivity" + tools:ignore="MergeRootFrame"> + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_drawer_item.xml b/app/src/main/res/layout/fragment_drawer_item.xml new file mode 100644 index 000000000..dc81adfbf --- /dev/null +++ b/app/src/main/res/layout/fragment_drawer_item.xml @@ -0,0 +1,13 @@ + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 72a0e8fd2..68ef83e68 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -100,6 +100,8 @@ All notes Single note + Drawer opened + Drawer closed diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 65dd8df89..f728202be 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,7 @@ - @@ -22,7 +22,7 @@ true -