From c810f3775a574ad2193550cc6db984fd4e90db3f Mon Sep 17 00:00:00 2001 From: geoffroy Date: Mon, 25 Jan 2016 17:42:14 -0500 Subject: [PATCH] All strings put in string.xml Long press does not drag task lists anymore Create task list button is themed Arrows are shown in the scrollable tabs Task form is now inside a scrollview (needs testing) Total cycles is now correctly reset when there are no more tasks --- DoNExt/app/build.gradle | 4 +- DoNExt/app/src/main/AndroidManifest.xml | 11 +- .../donext/activities/AboutActivity.java | 20 +++ .../donext/activities/MainActivity.java | 27 +++- .../donext/fragments/TasksFragment.java | 36 +++-- .../donext/helpers/TaskListTouchHelper.java | 2 +- .../src/main/res/layout/activity_about.xml | 15 ++ .../app/src/main/res/layout/activity_main.xml | 33 ++++- .../main/res/layout/fragment_task_form.xml | 133 +++++++++--------- .../main/res/layout/fragment_tasklists.xml | 1 + DoNExt/app/src/main/res/menu/menu_main.xml | 1 + DoNExt/app/src/main/res/values/strings.xml | 19 ++- DoNExt/app/src/main/res/values/styles.xml | 4 + 13 files changed, 215 insertions(+), 91 deletions(-) create mode 100644 DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/AboutActivity.java create mode 100644 DoNExt/app/src/main/res/layout/activity_about.xml diff --git a/DoNExt/app/build.gradle b/DoNExt/app/build.gradle index 894dda8..082391d 100644 --- a/DoNExt/app/build.gradle +++ b/DoNExt/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.wismna.geoffroy.donext" minSdkVersion 15 targetSdkVersion 23 - versionCode 7 - versionName "0.7" + versionCode 8 + versionName "0.8" } buildTypes { release { diff --git a/DoNExt/app/src/main/AndroidManifest.xml b/DoNExt/app/src/main/AndroidManifest.xml index 2f858af..246d258 100644 --- a/DoNExt/app/src/main/AndroidManifest.xml +++ b/DoNExt/app/src/main/AndroidManifest.xml @@ -14,12 +14,13 @@ android:theme="@style/AppTheme.NoActionBar"> + + + + diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/AboutActivity.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/AboutActivity.java new file mode 100644 index 0000000..a39c4b3 --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/AboutActivity.java @@ -0,0 +1,20 @@ +package com.wismna.geoffroy.donext.activities; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.TextView; + +import com.wismna.geoffroy.donext.BuildConfig; +import com.wismna.geoffroy.donext.R; + +public class AboutActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_about); + + TextView version = (TextView) findViewById(R.id.version); + version.setText(getResources().getString(R.string.about_version, BuildConfig.VERSION_NAME)); + } +} diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java index aee6a12..aae61de 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java @@ -2,6 +2,7 @@ package com.wismna.geoffroy.donext.activities; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Point; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; @@ -79,8 +80,26 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas PreferenceManager.getDefaultSharedPreferences(MainActivity.this); mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0)); - TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); + // TODO: hide arrows on start when not needed + final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); + tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() { + @Override + public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + // Hide left arrow when scrolled to the left + View leftArrow = findViewById(R.id.left_arrow); + if (scrollX <= 1) leftArrow.setVisibility(View.GONE); + else leftArrow.setVisibility(View.VISIBLE); + + // Hide right arrow when scrolled to the right + View rightArrow = findViewById(R.id.right_arrow); + Point size = new Point(); + getWindowManager().getDefaultDisplay().getSize(size); + if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - size.x) + rightArrow.setVisibility(View.GONE); + else rightArrow.setVisibility(View.VISIBLE); + } + }); // Hide or show new task floating button FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); @@ -183,6 +202,12 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas startActivity(intent); } + /** Called when the user clicks the About button */ + public void openAbout(MenuItem menuItem) { + Intent intent = new Intent(this, AboutActivity.class); + startActivity(intent); + } + private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) { TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position); if (taskFragment == null) return null; diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java index 3a644f2..8ee8d5d 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java @@ -3,6 +3,7 @@ package com.wismna.geoffroy.donext.fragments; import android.app.Dialog; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Resources; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.design.widget.Snackbar; @@ -122,7 +123,7 @@ public class TasksFragment extends Fragment implements ((MainActivity.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems(), TasksFragment.this); taskDialogFragment.setArguments(args); - taskDialogFragment.show(manager, "Edit task"); + taskDialogFragment.show(manager, getResources().getString(R.string.action_edit_task)); } }) ); @@ -131,27 +132,29 @@ public class TasksFragment extends Fragment implements recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { + // isAdded is tested to prevent an IllegalStateException when fast switching between tabs + if (!isAdded()) return true; + Resources resources = getResources(); + // Update total cycle count int totalCycles = taskRecyclerViewAdapter.getCycleCount(); - if (totalCycles != 0) { - TextView totalCyclesView = (TextView) view.findViewById(R.id.total_task_cycles); - totalCyclesView.setText(String.valueOf(totalCycles + " cycles")); - } + TextView totalCyclesView = (TextView) view.findViewById(R.id.total_task_cycles); + if (totalCycles != 0) + totalCyclesView.setText(resources.getString(R.string.task_total_cycles, totalCycles, (totalCycles > 1 ? "s" : ""))); + else totalCyclesView.setText(""); // Update total tasks int totalTasks = taskRecyclerViewAdapter.getItemCount(); TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count); - // isAdded is to prevent an IllegalStateException when fast switching between tabs - if (totalTasks == 0 && isAdded()) totalTasksView.setText(getResources().getText(R.string.task_no_tasks)); - else totalTasksView.setText(String.valueOf(totalTasks + " task" + (totalTasks > 1 ? "s" : ""))); + if (totalTasks == 0) totalTasksView.setText(resources.getText(R.string.task_no_tasks)); + else totalTasksView.setText(resources.getString(R.string.task_total, totalTasks, (totalTasks > 1 ? "s" : ""))); // Update remaining tasks TextView remainingTasksView = (TextView) view.findViewById(R.id.remaining_task_count); NoScrollingLayoutManager layoutManager = (NoScrollingLayoutManager) recyclerView.getLayoutManager(); int remainingTaskCount = totalTasks - layoutManager.findLastVisibleItemPosition() - 1; if (remainingTaskCount == 0) remainingTasksView.setText(""); - else remainingTasksView.setText(String.valueOf( - remainingTaskCount + " more task" + (remainingTaskCount > 1 ? "s" : ""))); + else remainingTasksView.setText(resources.getString(R.string.task_remaining, remainingTaskCount, (remainingTaskCount > 1 ? "s" : ""))); //recyclerView.getViewTreeObserver().removeOnPreDrawListener(this); return true; @@ -180,28 +183,30 @@ public class TasksFragment extends Fragment implements final long itemId = taskRecyclerViewAdapter.getItemId(itemPosition); final Task task = taskRecyclerViewAdapter.getItem(itemPosition); String action = ""; + Resources resources = getResources(); + taskRecyclerViewAdapter.remove(itemPosition); switch (direction) { // Mark item as Done case ItemTouchHelper.LEFT: - action = "done"; + action = resources.getString(R.string.snackabar_action_done); break; // Increase task cycle count case ItemTouchHelper.RIGHT: - action = "nexted"; + action = resources.getString(R.string.snackabar_action_next); task.setCycle(task.getCycle() + 1); taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount()); break; case -1: - action = "deleted"; + action = resources.getString(R.string.snackabar_action_deleted); break; } // Setup the snack bar - snackbar = Snackbar.make(view, "Task " + action, Snackbar.LENGTH_LONG) - .setAction("Undo", new View.OnClickListener() { + snackbar = Snackbar.make(view, resources.getString(R.string.snackabar_label, action), Snackbar.LENGTH_LONG) + .setAction(resources.getString(R.string.snackabar_button), new View.OnClickListener() { @Override public void onClick(View v) { // Undo adapter changes @@ -231,6 +236,7 @@ public class TasksFragment extends Fragment implements // When clicked on undo, do not write to DB if (event == DISMISS_EVENT_ACTION) return; + // TODO: correct bug when fast switching between tabs // Commit the changes to DB switch (direction) { diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/helpers/TaskListTouchHelper.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/helpers/TaskListTouchHelper.java index f0ba787..627b959 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/helpers/TaskListTouchHelper.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/helpers/TaskListTouchHelper.java @@ -33,7 +33,7 @@ public class TaskListTouchHelper extends ItemTouchHelper.SimpleCallback { @Override public boolean isLongPressDragEnabled() { - return true; + return false; } @Override diff --git a/DoNExt/app/src/main/res/layout/activity_about.xml b/DoNExt/app/src/main/res/layout/activity_about.xml new file mode 100644 index 0000000..1e16d29 --- /dev/null +++ b/DoNExt/app/src/main/res/layout/activity_about.xml @@ -0,0 +1,15 @@ + + + + diff --git a/DoNExt/app/src/main/res/layout/activity_main.xml b/DoNExt/app/src/main/res/layout/activity_main.xml index ba2ab0d..7fc86c5 100644 --- a/DoNExt/app/src/main/res/layout/activity_main.xml +++ b/DoNExt/app/src/main/res/layout/activity_main.xml @@ -23,12 +23,33 @@ app:layout_scrollFlags="enterAlways" app:popupTheme="@style/AppTheme.PopupOverlay" /> - - + + + + + - - + - - - - - - - - - - - + + + + + - - + + - - - + android:layout_height="wrap_content" + android:hint="@string/new_task_description_hint" + android:gravity="top|start" + android:lines="3"/> + + + + + + + + + + + \ No newline at end of file diff --git a/DoNExt/app/src/main/res/layout/fragment_tasklists.xml b/DoNExt/app/src/main/res/layout/fragment_tasklists.xml index 84ee3a6..315207a 100644 --- a/DoNExt/app/src/main/res/layout/fragment_tasklists.xml +++ b/DoNExt/app/src/main/res/layout/fragment_tasklists.xml @@ -27,6 +27,7 @@ android:id="@+id/new_task_list_button" android:layout_width="80dp" android:layout_height="wrap_content" + style="@style/Widget.AppCompat.Button.Colored" android:text="@string/task_list_new_list_create"/> diff --git a/DoNExt/app/src/main/res/values/strings.xml b/DoNExt/app/src/main/res/values/strings.xml index 781a581..578189b 100644 --- a/DoNExt/app/src/main/res/values/strings.xml +++ b/DoNExt/app/src/main/res/values/strings.xml @@ -6,8 +6,12 @@ Edit lists About New task + Edit task Change layout - Settings + + + Left scroll arrow + Right scroll arrow New list name @@ -35,6 +39,16 @@ Details Yeah! No more tasks! + %1$d cycle%2$s + %1$d task%2$s + %1$d more task%2$s + + + Task %s + done + nexted + deleted + Undo Mark task as Done? @@ -74,4 +88,7 @@ 7 TaskListActivity + + + Version %s diff --git a/DoNExt/app/src/main/res/values/styles.xml b/DoNExt/app/src/main/res/values/styles.xml index 545b9c6..66831e5 100644 --- a/DoNExt/app/src/main/res/values/styles.xml +++ b/DoNExt/app/src/main/res/values/styles.xml @@ -17,4 +17,8 @@