diff --git a/app/src/androidTest/java/org/standardnotes/notes/StarterActivityTest.java b/app/src/androidTest/java/org/standardnotes/notes/StarterActivityTest.java index 7c99e87..522a5e3 100644 --- a/app/src/androidTest/java/org/standardnotes/notes/StarterActivityTest.java +++ b/app/src/androidTest/java/org/standardnotes/notes/StarterActivityTest.java @@ -8,20 +8,11 @@ import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; - -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.standardnotes.notes.comms.data.Tag; import java.util.UUID; @@ -31,9 +22,7 @@ import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard; import static android.support.test.espresso.action.ViewActions.replaceText; import static android.support.test.espresso.action.ViewActions.scrollTo; -import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; import static android.support.test.espresso.assertion.ViewAssertions.matches; -import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItem; import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription; @@ -41,6 +30,9 @@ import static android.support.test.espresso.matcher.ViewMatchers.withParent; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.anyOf; +import static org.hamcrest.Matchers.not; +import static org.standardnotes.notes.TestHelper.childAtPosition; @LargeTest @RunWith(AndroidJUnit4.class) @@ -97,12 +89,9 @@ public void signupin() { Espresso.unregisterIdlingResources(idlingResource); } - - @After public void logout() { - ViewInteraction actionMenuItemView = onView( - allOf(withId(R.id.settings), withContentDescription("Settings"), isDisplayed())); + ViewInteraction actionMenuItemView = onView(allOf(withId(R.id.settings), isDisplayed())); actionMenuItemView.perform(click()); ViewInteraction appCompatButton = onView( @@ -112,13 +101,8 @@ public void logout() { @Test public void createNote() { - - ViewInteraction floatingActionButton = onView( - allOf(withId(R.id.fab), - withParent(allOf(withId(R.id.rootView), - withParent(withId(R.id.drawer_layout)))), - isDisplayed())); - floatingActionButton.perform(click()); + ViewInteraction newNoteButton = onView(anyOf(withId(R.id.fab_new_note), withId(R.id.new_note))); + newNoteButton.perform(click()); ViewInteraction appCompatEditText = onView( withId(R.id.titleEdit)); @@ -132,17 +116,12 @@ public void createNote() { allOf(withId(R.id.bodyEdit))); appCompatEditText14.perform(scrollTo(), replaceText("body1"), closeSoftKeyboard()); - ViewInteraction upButton = onView( - allOf(withContentDescription("Navigate up"), - withParent(withId(R.id.toolbar)), - isDisplayed())); - upButton.perform(click()); + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); + } ViewInteraction recyclerView = onView( - allOf(withId(R.id.list), - withParent(allOf(withId(R.id.noteListFrag), - withParent(withId(R.id.rootView)))), - isDisplayed())); + allOf(withId(R.id.list_note), isDisplayed())); recyclerView.perform(actionOnItemAtPosition(0, click())); ViewInteraction actionMenuItemView = onView( @@ -153,13 +132,15 @@ public void createNote() { appCompatEditText14.perform(scrollTo(), replaceText("body1a"), closeSoftKeyboard()); - upButton.perform(click()); + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); + } ViewInteraction textView = onView( allOf(withId(R.id.text), withText("body1a"), childAtPosition( childAtPosition( - withId(R.id.list), + withId(R.id.list_note), 0), 1), isDisplayed())); @@ -169,7 +150,7 @@ public void createNote() { allOf(withId(R.id.title), withText("Title1"), childAtPosition( childAtPosition( - withId(R.id.list), + withId(R.id.list_note), 0), 0), isDisplayed())); @@ -188,12 +169,8 @@ public void justSignInAndOut() { @Test public void tagSomething() { - ViewInteraction floatingActionButton = onView( - allOf(withId(R.id.fab), - withParent(allOf(withId(R.id.rootView), - withParent(withId(R.id.drawer_layout)))), - isDisplayed())); - floatingActionButton.perform(click()); + ViewInteraction newNoteButton = onView(anyOf(withId(R.id.fab_new_note), withId(R.id.new_note))); + newNoteButton.perform(click()); ViewInteraction appCompatEditText = onView( withId(R.id.titleEdit)); @@ -210,12 +187,12 @@ public void tagSomething() { ViewInteraction tagsAction = onView( allOf(withId(R.id.tags), withContentDescription("Tags"), isDisplayed())); tagsAction.perform(click()); - onView(withId(R.id.fab)).perform(click()); + onView(withId(R.id.fab_new_tag)).perform(click()); onView( allOf(withId(R.id.tag), isDisplayed())).perform(replaceText("tag1"), closeSoftKeyboard()); onView( allOf(withId(android.R.id.button1), withText("OK"))).perform(scrollTo(), click()); - onView(withId(R.id.fab)).perform(click()); + onView(withId(R.id.fab_new_tag)).perform(click()); onView( allOf(withId(R.id.tag), isDisplayed())).perform(replaceText("tag2"), closeSoftKeyboard()); onView( @@ -225,22 +202,17 @@ public void tagSomething() { pressBack(); - ViewInteraction upButton = onView( - allOf(withContentDescription("Navigate up"), - withParent(withId(R.id.toolbar)), - isDisplayed())); - upButton.perform(click()); + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); + } logout(); signupin(); ViewInteraction recyclerView = onView( - allOf(withId(R.id.list), - withParent(allOf(withId(R.id.noteListFrag), - withParent(withId(R.id.rootView)))), - isDisplayed())); + allOf(withId(R.id.list_note), isDisplayed())); recyclerView.perform(actionOnItemAtPosition(0, click())); - onView(withText("tag1")).check(matches(isDisplayed())); + onView(allOf(withText("tag1"), withId(R.id.tagText))).check(matches(isDisplayed())); tagsAction.perform(click()); onView( @@ -248,30 +220,29 @@ public void tagSomething() { onView( withText("tag2")).perform(click()); // select pressBack(); - onView(withText("tag2")).check(matches(isDisplayed())); - onView(withText("tag1")).check(doesNotExist()); - pressBack(); + onView(allOf(withText("tag2"), withId(R.id.tagText))).check(matches(isDisplayed())); + onView(withText("tag1")).check(matches(not(isDisplayed()))); + + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); + } logout(); signupin(); recyclerView.perform(actionOnItemAtPosition(0, click())); - onView(withText("tag2")).check(matches(isDisplayed())); - onView(withText("tag1")).check(doesNotExist()); - + onView(allOf(withText("tag2"), withId(R.id.tagText))).check(matches(isDisplayed())); + onView(withText("tag1")).check(matches(not(isDisplayed()))); - pressBack(); + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); + } } @Test public void openCloseOpenClose() { - - ViewInteraction floatingActionButton = onView( - allOf(withId(R.id.fab), - withParent(allOf(withId(R.id.rootView), - withParent(withId(R.id.drawer_layout)))), - isDisplayed())); - floatingActionButton.perform(click()); + ViewInteraction newNoteButton = onView(anyOf(withId(R.id.fab_new_note), withId(R.id.new_note))); + newNoteButton.perform(click()); ViewInteraction appCompatEditText = onView( withId(R.id.titleEdit)); @@ -284,57 +255,21 @@ public void openCloseOpenClose() { ViewInteraction appCompatEditText14 = onView( allOf(withId(R.id.bodyEdit))); appCompatEditText14.perform(scrollTo(), replaceText("body2"), closeSoftKeyboard()); - pressBack(); - - ViewInteraction recyclerView = onView( - allOf(withId(R.id.list), - withParent(allOf(withId(R.id.noteListFrag), - withParent(withId(R.id.rootView)))), - isDisplayed())); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - recyclerView.perform(actionOnItemAtPosition(0, click())); - pressBack(); - } + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); + } - private static Matcher childAtPosition( - final Matcher parentMatcher, final int position) { - - return new TypeSafeMatcher() { - @Override - public void describeTo(Description description) { - description.appendText("Child at position " + position + " in parent "); - parentMatcher.describeTo(description); - } + ViewInteraction recyclerView = onView( + allOf(withId(R.id.list_note), isDisplayed())); - @Override - public boolean matchesSafely(View view) { - ViewParent parent = view.getParent(); - return parent instanceof ViewGroup && parentMatcher.matches(parent) - && view.equals(((ViewGroup) parent).getChildAt(position)); + int i = 0; + do { + recyclerView.perform(actionOnItemAtPosition(0, click())); + if (!TestHelper.isScreenW600dp(mActivityTestRule.getActivity())) { + pressBack(); } - }; + i++; + } while (i < 10); } - } diff --git a/app/src/androidTest/java/org/standardnotes/notes/TestHelper.java b/app/src/androidTest/java/org/standardnotes/notes/TestHelper.java new file mode 100644 index 0000000..78e95ea --- /dev/null +++ b/app/src/androidTest/java/org/standardnotes/notes/TestHelper.java @@ -0,0 +1,39 @@ +package org.standardnotes.notes; + +import android.app.Activity; +import android.util.DisplayMetrics; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; + +public class TestHelper { + + public static Matcher childAtPosition( + final Matcher parentMatcher, final int position) { + + return new TypeSafeMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Child at position " + position + " in parent "); + parentMatcher.describeTo(description); + } + + @Override + public boolean matchesSafely(View view) { + ViewParent parent = view.getParent(); + return parent instanceof ViewGroup && parentMatcher.matches(parent) + && view.equals(((ViewGroup) parent).getChildAt(position)); + } + }; + } + + public static boolean isScreenW600dp(Activity activity) { + DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics(); + float widthDp = displayMetrics.widthPixels / displayMetrics.density; + return widthDp >= 600; + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 16f77f0..3a135f3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -30,11 +30,6 @@ android:name=".MainActivity" android:label="@string/title_activity_main" android:theme="@style/AppTheme.NoActionBar" /> - diff --git a/app/src/main/java/org/standardnotes/notes/MainActivity.kt b/app/src/main/java/org/standardnotes/notes/MainActivity.kt index 6d32c20..aead60d 100644 --- a/app/src/main/java/org/standardnotes/notes/MainActivity.kt +++ b/app/src/main/java/org/standardnotes/notes/MainActivity.kt @@ -3,42 +3,41 @@ package org.standardnotes.notes import android.content.Intent import android.content.res.Configuration import android.os.Bundle +import android.support.v4.app.FragmentManager import android.support.v7.app.ActionBarDrawerToggle import android.view.Menu import android.view.MenuItem -import android.view.MotionEvent import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.view_navigation_header.view.* import org.standardnotes.notes.comms.SyncManager -import org.standardnotes.notes.comms.data.Note +import org.standardnotes.notes.frag.NoteFragment import org.standardnotes.notes.frag.NoteListFragment -class MainActivity : BaseActivity(), SyncManager.SyncListener { +class MainActivity : BaseActivity(), SyncManager.SyncListener, NoteListFragment.OnNewNoteClickListener, NoteFragment.DetachListener { - override fun onSyncStarted() { - } + val TAG_NOTE_FRAGMENT = "note_fragment" + val TAG_NOTE_LIST_FRAGMENT = "note_list_fragment" + val EXTRA_TAG = "tag" - override fun onSyncFailed() { - onSyncCompleted() - } + private lateinit var noteListFragment: NoteListFragment + private var noteFragment: NoteFragment? = null - override fun onSyncCompleted() { - updateTagsMenu() // Update tags list - noteListFragment().refreshNotesForTag(selectedTagId) // Update notes in fragment - } + private lateinit var drawerToggle: ActionBarDrawerToggle + private var selectedTagId = "" override fun onSaveInstanceState(outState: Bundle?) { super.onSaveInstanceState(outState) - outState!!.putString("tag", selectedTagId) + outState!!.putString(EXTRA_TAG, selectedTagId) + supportFragmentManager.putFragment(outState, TAG_NOTE_LIST_FRAGMENT, noteListFragment) + if (supportFragmentManager.findFragmentByTag(TAG_NOTE_FRAGMENT) != null ) { + supportFragmentManager.putFragment(outState, TAG_NOTE_FRAGMENT, noteFragment) + } } - private lateinit var drawerToggle: ActionBarDrawerToggle - private var selectedTagId = "" - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (savedInstanceState != null && savedInstanceState?.containsKey("tag")) { - selectedTagId = savedInstanceState.getString("tag") + if (savedInstanceState != null && savedInstanceState?.containsKey(EXTRA_TAG)) { + selectedTagId = savedInstanceState.getString(EXTRA_TAG) } setContentView(R.layout.activity_main) @@ -46,33 +45,59 @@ class MainActivity : BaseActivity(), SyncManager.SyncListener { drawerToggle = ActionBarDrawerToggle(this, drawer_layout, R.string.app_name, R.string.app_name) drawer_layout.addDrawerListener(drawerToggle!!) - drawerToggle.isDrawerIndicatorEnabled = true - supportActionBar?.setDisplayHomeAsUpEnabled(true) - supportActionBar?.setHomeButtonEnabled(true) + addDrawerToggle() + + if (savedInstanceState == null) { + noteListFragment = NoteListFragment() + supportFragmentManager + .beginTransaction() + .replace(R.id.master_container, noteListFragment, TAG_NOTE_LIST_FRAGMENT) + .commit() + } else { + noteListFragment = supportFragmentManager.findFragmentByTag(TAG_NOTE_LIST_FRAGMENT) as NoteListFragment + noteFragment = supportFragmentManager.findFragmentByTag(TAG_NOTE_FRAGMENT) as? NoteFragment + noteFragment?.detachListener = this + + if (noteFragment != null) { + supportFragmentManager + .popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE) + supportFragmentManager + .beginTransaction() + .remove(noteFragment) + .commitNow() + + if (findViewById(R.id.detail_container) != null) { + supportFragmentManager + .beginTransaction() + .remove(noteListFragment) + .commitNow() + + supportFragmentManager + .beginTransaction() + .add(R.id.master_container, noteListFragment, TAG_NOTE_LIST_FRAGMENT) + .replace(R.id.detail_container, noteFragment, TAG_NOTE_FRAGMENT) + .commit() + + } else { + + removeDrawerToggle() + supportFragmentManager + .beginTransaction() + .add(R.id.master_container, noteFragment, TAG_NOTE_FRAGMENT) + .addToBackStack(null) + .commit() + } + } + } + + noteListFragment.onNewNoteListener = this + val header = drawer.inflateHeaderView(R.layout.view_navigation_header) val values = SApplication.instance.valueStore header.main_account_server.text = values.server header.main_account_email.text = values.email title = getString(R.string.app_name) - - var lastX: Int? = null - var lastY: Int? = null - fab.setOnTouchListener({ v, event -> - if (event.action == MotionEvent.ACTION_UP) { - lastX = event.rawX.toInt() - lastY = event.rawY.toInt() - } - false - }) - fab.setOnClickListener { view -> - noteListFragment().startNewNote(lastX!!, lastY!!, selectedTagId) - } - - } - - fun noteListFragment(): NoteListFragment { - return supportFragmentManager.findFragmentById(R.id.noteListFrag) as NoteListFragment } fun updateTagsMenu() { @@ -82,7 +107,7 @@ class MainActivity : BaseActivity(), SyncManager.SyncListener { drawer_layout.closeDrawers() selectedTagId = uuid updateTagsMenu() - noteListFragment().refreshNotesForTag(selectedTagId) + noteListFragment.refreshNotesForTag(selectedTagId) return@setOnMenuItemClickListener true } } @@ -107,6 +132,39 @@ class MainActivity : BaseActivity(), SyncManager.SyncListener { selectedTagId = selectedId // In case selected tag wasn't found in list } + fun removeDrawerToggle() { + drawerToggle.isDrawerIndicatorEnabled = false + supportActionBar?.setDisplayHomeAsUpEnabled(false) + supportActionBar?.setHomeButtonEnabled(false) + } + + override fun addDrawerToggle() { + drawerToggle.isDrawerIndicatorEnabled = true + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setHomeButtonEnabled(true) + } + + override fun newNoteListener(uuid: String) { + noteFragment = NoteFragment() + noteFragment!!.detachListener = this + val bundle = Bundle() + bundle.putString(NoteListFragment.EXTRA_NOTE_ID, uuid) + noteFragment!!.arguments = bundle + if (findViewById(R.id.detail_container) == null) { + removeDrawerToggle() + supportFragmentManager + .beginTransaction() + .add(R.id.master_container, noteFragment, TAG_NOTE_FRAGMENT) + .addToBackStack(null) + .commit() + } else { + supportFragmentManager + .beginTransaction() + .replace(R.id.detail_container, noteFragment, TAG_NOTE_FRAGMENT) + .commit() + } + } + override fun onResume() { super.onResume() SyncManager.startSyncTimer() @@ -120,10 +178,6 @@ class MainActivity : BaseActivity(), SyncManager.SyncListener { SyncManager.unsubscribe(this) } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - } - override fun onCreateOptionsMenu(menu: Menu): Boolean { super.onCreateOptionsMenu(menu) menuInflater.inflate(R.menu.logged_in, menu) @@ -141,10 +195,9 @@ class MainActivity : BaseActivity(), SyncManager.SyncListener { R.id.settings -> startActivity(Intent(this, SettingsActivity::class.java)) R.id.debug -> startActivity(Intent(this, DebugActivity::class.java)) } - return true + return false } - override fun onConfigurationChanged(newConfig: Configuration?) { super.onConfigurationChanged(newConfig) drawerToggle?.syncState() @@ -155,4 +208,15 @@ class MainActivity : BaseActivity(), SyncManager.SyncListener { drawerToggle?.syncState() } + override fun onSyncStarted() { + } + + override fun onSyncFailed() { + onSyncCompleted() + } + + override fun onSyncCompleted() { + updateTagsMenu() + noteListFragment.refreshNotesForTag(selectedTagId) + } } diff --git a/app/src/main/java/org/standardnotes/notes/NoteActivity.kt b/app/src/main/java/org/standardnotes/notes/NoteActivity.kt deleted file mode 100644 index 7c9cc89..0000000 --- a/app/src/main/java/org/standardnotes/notes/NoteActivity.kt +++ /dev/null @@ -1,105 +0,0 @@ -package org.standardnotes.notes - -import android.animation.Animator -import android.content.Intent -import android.os.Bundle -import android.support.v4.app.NavUtils -import android.view.* -import org.standardnotes.notes.frag.NoteFragment -import org.standardnotes.notes.frag.NoteListFragment.Companion.EXTRA_NOTE_ID -import org.standardnotes.notes.frag.NoteListFragment.Companion.EXTRA_X_COOR -import org.standardnotes.notes.frag.NoteListFragment.Companion.EXTRA_Y_COOR - -class NoteActivity : BaseActivity() { - - val REVEAL_ANIM_DURATION = 200L - var revealX: Int = 0 - var revealY: Int = 0 - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - overridePendingTransition(0, 0) - - revealX = intent.getIntExtra(EXTRA_X_COOR, 0) - revealY = intent.getIntExtra(EXTRA_Y_COOR, 0) - if (savedInstanceState == null) { - val frag: NoteFragment = NoteFragment() - frag.arguments = intent.extras - - supportFragmentManager.beginTransaction().replace(android.R.id.content, frag).commit() - - if (revealX != 0) { - - val rootView = findViewById(android.R.id.content) - val viewTreeObserver = rootView.viewTreeObserver - if (viewTreeObserver.isAlive) { - rootView.visibility = View.INVISIBLE - viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - circularReveal() - rootView.viewTreeObserver.removeOnGlobalLayoutListener(this) - } - }) - } - } - } - if (intent.extras.getString(EXTRA_NOTE_ID) == null) { - window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) - } - } - - override fun onBackPressed() { - overridePendingTransition(0, 0) - if (revealX != 0) { - circularHide() - } else { - super.onBackPressed() - } - } - - private fun circularReveal() { - val rootView = findViewById(android.R.id.content) - val circularReveal = ViewAnimationUtils.createCircularReveal(rootView, revealX, revealY, 0f, Math.max(rootView.width, rootView.height).toFloat()) - circularReveal.duration = REVEAL_ANIM_DURATION - rootView.visibility = View.VISIBLE - circularReveal.start() - } - - private fun circularHide() { - val rootView = findViewById(android.R.id.content) - val circularHide = ViewAnimationUtils.createCircularReveal(rootView, revealX, revealY, Math.max(rootView.width, rootView.height).toFloat(), 0f) - circularHide.duration = REVEAL_ANIM_DURATION - circularHide.addListener(object : Animator.AnimatorListener { - override fun onAnimationStart(animation: Animator) { - // - } - - override fun onAnimationRepeat(animation: Animator) { - // - } - - override fun onAnimationEnd(animation: Animator) { - rootView.visibility = View.GONE - overridePendingTransition(0, 0) - finish() - } - - override fun onAnimationCancel(animation: Animator) { - // - } - }) - circularHide.start() - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == android.R.id.home) { - if (NavUtils.getParentActivityIntent(this) != null) { - NavUtils.navigateUpTo(this, NavUtils.getParentActivityIntent(this).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) - } else { - onBackPressed() - } - return true - } - return super.onOptionsItemSelected(item) - } -} \ No newline at end of file diff --git a/app/src/main/java/org/standardnotes/notes/StarterActivity.kt b/app/src/main/java/org/standardnotes/notes/StarterActivity.kt index 0f100a3..dd94331 100644 --- a/app/src/main/java/org/standardnotes/notes/StarterActivity.kt +++ b/app/src/main/java/org/standardnotes/notes/StarterActivity.kt @@ -15,7 +15,7 @@ class StarterActivity : AppCompatActivity() { if (intent.action == Intent.ACTION_SEND && intent.type == "text/plain") { var text = intent.getStringExtra(Intent.EXTRA_TEXT) if (text != null) { - val intent = Intent(this, NoteActivity::class.java) + val intent = Intent(this, MainActivity::class.java) intent.putExtra(EXTRA_TEXT, text) startActivity(intent) } diff --git a/app/src/main/java/org/standardnotes/notes/TagListActivity.kt b/app/src/main/java/org/standardnotes/notes/TagListActivity.kt index 7090e5b..db5a224 100644 --- a/app/src/main/java/org/standardnotes/notes/TagListActivity.kt +++ b/app/src/main/java/org/standardnotes/notes/TagListActivity.kt @@ -42,10 +42,10 @@ class TagListActivity : BaseActivity() { selectedTags = selectedTagsList.toSet() tags = app.noteStore.getAllTags(false).sortedBy { it.title.toLowerCase() } - list.adapter = Adapter() - list.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) + list_tag.adapter = Adapter() + list_tag.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) - fab.setOnClickListener { + fab_new_tag.setOnClickListener { val layout = LayoutInflater.from(this).inflate(R.layout.view_new_tag, null, false) val input = layout.findViewById(R.id.tag) as EditText val dialog = AlertDialog.Builder(this).setTitle(R.string.prompt_new_tag) @@ -57,7 +57,7 @@ class TagListActivity : BaseActivity() { app.noteStore.putTag(newTag.uuid, newTag) SyncManager.sync() tags = app.noteStore.getAllTags(false) - list.adapter.notifyDataSetChanged() + list_tag.adapter.notifyDataSetChanged() }) .setView(layout) .show() diff --git a/app/src/main/java/org/standardnotes/notes/frag/NoteFragment.kt b/app/src/main/java/org/standardnotes/notes/frag/NoteFragment.kt index 2956055..da32747 100644 --- a/app/src/main/java/org/standardnotes/notes/frag/NoteFragment.kt +++ b/app/src/main/java/org/standardnotes/notes/frag/NoteFragment.kt @@ -15,10 +15,7 @@ import com.google.gson.reflect.TypeToken import kotlinx.android.synthetic.main.frag_note.* import kotlinx.android.synthetic.main.item_tag_lozenge.view.* import org.joda.time.DateTime -import org.standardnotes.notes.EXTRA_TAGS -import org.standardnotes.notes.R -import org.standardnotes.notes.SApplication -import org.standardnotes.notes.TagListActivity +import org.standardnotes.notes.* import org.standardnotes.notes.comms.Crypt import org.standardnotes.notes.comms.SyncManager import org.standardnotes.notes.comms.data.ContentType @@ -43,28 +40,26 @@ class NoteFragment : Fragment(), SyncManager.SyncListener { lateinit var note: Note lateinit var tags: List + var detachListener: DetachListener? = null - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setHasOptionsMenu(true) - } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setHasOptionsMenu(true) + } - override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = inflater!!.inflate(R.layout.frag_note, container, false) - return view + override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { + val view = inflater!!.inflate(R.layout.frag_note, container, false) + return view } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val context = activity as AppCompatActivity - context.setSupportActionBar(toolbar) - context.supportActionBar?.setDisplayShowHomeEnabled(true) - context.supportActionBar?.setDisplayHomeAsUpEnabled(true) + activity.setTitle(R.string.title_activity_note) val noteUuid = savedInstanceState?.getString(NoteListFragment.EXTRA_NOTE_ID) ?: arguments?.getString(NoteListFragment.EXTRA_NOTE_ID) - if (noteUuid != null) { + if (noteUuid != null && noteUuid != "") { note = SApplication.instance.noteStore.getNote(noteUuid)!! tags = SApplication.instance.noteStore.getTagsForNote(noteUuid) } else { @@ -170,6 +165,12 @@ class NoteFragment : Fragment(), SyncManager.SyncListener { inflater.inflate(R.menu.note, menu) } + override fun onPrepareOptionsMenu(menu: Menu) { + super.onPrepareOptionsMenu(menu) + menu.clear() + activity.menuInflater.inflate(R.menu.note, menu) + } + override fun onOptionsItemSelected(item: MenuItem?): Boolean { when (item?.itemId) { R.id.tags -> { @@ -229,6 +230,15 @@ class NoteFragment : Fragment(), SyncManager.SyncListener { setSubtitle(getString(R.string.sync_progress_error)) } + override fun onDetach() { + super.onDetach() + activity.setTitle(R.string.app_name) + detachListener?.addDrawerToggle() + } + + interface DetachListener { + fun addDrawerToggle() + } } fun newNote(): Note { diff --git a/app/src/main/java/org/standardnotes/notes/frag/NoteListFragment.kt b/app/src/main/java/org/standardnotes/notes/frag/NoteListFragment.kt index 37d8bf9..6c0ed53 100644 --- a/app/src/main/java/org/standardnotes/notes/frag/NoteListFragment.kt +++ b/app/src/main/java/org/standardnotes/notes/frag/NoteListFragment.kt @@ -1,6 +1,5 @@ package org.standardnotes.notes.frag -import android.content.Intent import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v4.app.Fragment @@ -9,21 +8,18 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.PopupMenu import android.support.v7.widget.RecyclerView import android.text.TextUtils -import android.view.LayoutInflater -import android.view.MotionEvent -import android.view.View -import android.view.ViewGroup +import android.view.* import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.frag_note_list.* +import kotlinx.android.synthetic.main.frag_note_list.view.* import kotlinx.android.synthetic.main.item_note.view.* import org.joda.time.format.DateTimeFormat -import org.standardnotes.notes.NoteActivity import org.standardnotes.notes.R import org.standardnotes.notes.SApplication import org.standardnotes.notes.comms.SyncManager import org.standardnotes.notes.comms.data.Note import java.util.* - +import android.view.MenuInflater class NoteListFragment : Fragment(), SyncManager.SyncListener { @@ -31,12 +27,15 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { var notes = ArrayList() var tagId = "" + var selectedTagId = "" var currentSnackbar: Snackbar? = null var lastTouchedX: Int? = null var lastTouchedY: Int? = null + lateinit var onNewNoteListener: OnNewNoteClickListener + companion object { const val EXTRA_NOTE_ID = "noteId" const val EXTRA_TAG_ID = "tagId" @@ -44,30 +43,26 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { const val EXTRA_Y_COOR = "yCoor" } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - if (savedInstanceState != null) { - tagId = savedInstanceState.getString("tagId") - } - } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.frag_note_list, container, false) + setHasOptionsMenu(true) + setFabClickListener(view) + return view } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) SyncManager.subscribe(this) - list.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) - list.addItemDecoration(DividerItemDecoration(activity, LinearLayoutManager.VERTICAL)) + list_note.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) + list_note.addItemDecoration(DividerItemDecoration(activity, LinearLayoutManager.VERTICAL)) swipeRefreshLayout.setColorSchemeResources( R.color.colorPrimary, R.color.colorAccent) swipeRefreshLayout.setOnRefreshListener { SyncManager.sync() } SyncManager.sync() - list.adapter = adapter + list_note.adapter = adapter } override fun onDestroyView() { @@ -80,9 +75,32 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { refreshNotesForTag() // This is too often and slow for large datasets, but necessary until we have an event to trigger refresh } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.note_list, menu) + super.onCreateOptionsMenu(menu, inflater) + } + + override fun onOptionsItemSelected(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.new_note -> startNewNote(selectedTagId) + } + + return super.onOptionsItemSelected(item) + } + override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putString("tagId", tagId) + outState.putString("tag", selectedTagId) + } + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + + if (savedInstanceState != null) { + tagId = savedInstanceState.getString("tagId") + selectedTagId = savedInstanceState.getString("tag") + } } override fun onSyncStarted() { @@ -95,6 +113,25 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { currentSnackbar?.dismiss() } + fun setFabClickListener(view: View) { + if (view.fab_new_note == null) { + return + } + + var lastX: Int? = null + var lastY: Int? = null + view.fab_new_note.setOnTouchListener({ v, event -> + if (event.action == MotionEvent.ACTION_UP) { + lastX = event.rawX.toInt() + lastY = event.rawY.toInt() + } + false + }) + view.fab_new_note.setOnClickListener { view -> + startNewNote(selectedTagId) + } + } + fun refreshNotesForTag(uuid: String? = null) { if (uuid == null) { // In-place refresh after delete refreshNotesForTag(tagId) @@ -119,12 +156,12 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { currentSnackbar!!.show() } - fun startNewNote(x: Int, y: Int, uuid: String) { - val intent: Intent = Intent(activity, NoteActivity::class.java) - intent.putExtra(EXTRA_X_COOR, x) - intent.putExtra(EXTRA_Y_COOR, y) - intent.putExtra(EXTRA_TAG_ID, uuid) - startActivity(intent) + fun startNewNote(uuid: String) { + onNewNoteListener.newNoteListener(uuid) + } + + interface OnNewNoteClickListener { + fun newNoteListener(uuid: String) } inner class NoteHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { @@ -151,11 +188,7 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { false }) itemView.setOnClickListener { - val intent: Intent = Intent(activity, NoteActivity::class.java) - intent.putExtra(EXTRA_NOTE_ID, note?.uuid) - intent.putExtra(EXTRA_X_COOR, lastTouchedX) - intent.putExtra(EXTRA_Y_COOR, lastTouchedY) - startActivity(intent) + onNewNoteListener.newNoteListener(note!!.uuid) } itemView.setOnLongClickListener { val popup = PopupMenu(activity, itemView) @@ -186,6 +219,5 @@ class NoteListFragment : Fragment(), SyncManager.SyncListener { val note: Note = notes[position] holder.note = note } - } } diff --git a/app/src/main/res/layout-w600dp/frag_note_list.xml b/app/src/main/res/layout-w600dp/frag_note_list.xml new file mode 100644 index 0000000..2f862ed --- /dev/null +++ b/app/src/main/res/layout-w600dp/frag_note_list.xml @@ -0,0 +1,24 @@ + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ed21f01..95778b3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -27,19 +27,8 @@ app:subtitleTextAppearance="@style/ToolbarSubtitleAppearance" /> - - + + - @@ -8,14 +8,14 @@ + android:scrollbarStyle="outsideInset" + android:background="@android:color/white"> - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/frag_note_list.xml b/app/src/main/res/layout/frag_note_list.xml index 1ef6a49..3593b24 100644 --- a/app/src/main/res/layout/frag_note_list.xml +++ b/app/src/main/res/layout/frag_note_list.xml @@ -1,20 +1,36 @@ - - - + android:layout_height="match_parent"> + + + + + + + + diff --git a/app/src/main/res/layout/single_pane_container.xml b/app/src/main/res/layout/single_pane_container.xml new file mode 100644 index 0000000..42d6727 --- /dev/null +++ b/app/src/main/res/layout/single_pane_container.xml @@ -0,0 +1,8 @@ + + diff --git a/app/src/main/res/layout/two_pane_container.xml b/app/src/main/res/layout/two_pane_container.xml new file mode 100644 index 0000000..232f51e --- /dev/null +++ b/app/src/main/res/layout/two_pane_container.xml @@ -0,0 +1,23 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu-w600dp/note.xml b/app/src/main/res/menu-w600dp/note.xml new file mode 100644 index 0000000..ca9f94b --- /dev/null +++ b/app/src/main/res/menu-w600dp/note.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu-w600dp/note_list.xml b/app/src/main/res/menu-w600dp/note_list.xml new file mode 100644 index 0000000..1ed3cdd --- /dev/null +++ b/app/src/main/res/menu-w600dp/note_list.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/logged_in.xml b/app/src/main/res/menu/logged_in.xml index ebec3e1..2dc5fcb 100644 --- a/app/src/main/res/menu/logged_in.xml +++ b/app/src/main/res/menu/logged_in.xml @@ -6,12 +6,14 @@ android:id="@+id/debug" android:title="Debug" app:showAsAction="ifRoom" + android:orderInCategory="10" android:visible="false" /> \ No newline at end of file diff --git a/app/src/main/res/menu/note.xml b/app/src/main/res/menu/note.xml index 6635b75..daf63d5 100644 --- a/app/src/main/res/menu/note.xml +++ b/app/src/main/res/menu/note.xml @@ -5,6 +5,7 @@ diff --git a/app/src/main/res/menu/note_list.xml b/app/src/main/res/menu/note_list.xml new file mode 100644 index 0000000..fe187c0 --- /dev/null +++ b/app/src/main/res/menu/note_list.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values-w600dp/refs.xml b/app/src/main/res/values-w600dp/refs.xml new file mode 100644 index 0000000..4d76c8c --- /dev/null +++ b/app/src/main/res/values-w600dp/refs.xml @@ -0,0 +1,4 @@ + + + @layout/two_pane_container + \ No newline at end of file diff --git a/app/src/main/res/values/refs.xml b/app/src/main/res/values/refs.xml new file mode 100644 index 0000000..eddce12 --- /dev/null +++ b/app/src/main/res/values/refs.xml @@ -0,0 +1,4 @@ + + + @layout/single_pane_container + \ 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 8171f1a..707feed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,5 +60,6 @@ Export Data Data export failed. Share File + New Note