mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 07:30:13 -04:00
About page update to show SDK version
TaskDataAccess now implements AutoCloseable Correction of TaskDataAccess exception due to closing when SnackBar was present and tabs were fast switched Detection of initial scroll value to toggle arrows visibility (but there is still an issue with right arrow)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.wismna.geoffroy.donext.activities;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.TextView;
|
||||
@@ -14,7 +15,11 @@ public class AboutActivity extends AppCompatActivity {
|
||||
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));
|
||||
TextView versionDonext = (TextView) findViewById(R.id.version_donext);
|
||||
versionDonext.setText(getResources().getString(R.string.about_version_donext, BuildConfig.VERSION_NAME));
|
||||
|
||||
TextView versionAndroid = (TextView) findViewById(R.id.version_android);
|
||||
versionAndroid.setText(getResources().getString(R.string.about_version_android, Build.VERSION.SDK_INT));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package com.wismna.geoffroy.donext.activities;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Point;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
@@ -44,6 +45,7 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
private TabLayout tabLayout;
|
||||
private List<TaskList> taskLists;
|
||||
|
||||
@Override
|
||||
@@ -80,26 +82,20 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
||||
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
||||
mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0));
|
||||
|
||||
// TODO: hide arrows on start when not needed
|
||||
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||
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);
|
||||
}
|
||||
});
|
||||
toggleTabLayoutArrows(tabLayout.getScrollX());
|
||||
// Handles scroll detection (only available for SDK version >=23)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
//tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT);
|
||||
tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||
@Override
|
||||
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
toggleTabLayoutArrows(scrollX);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Hide or show new task floating button
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
@@ -218,6 +214,23 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
||||
return (TaskRecyclerViewAdapter) recyclerView.getAdapter();
|
||||
}
|
||||
|
||||
/** Toggles scrolling arrows visibility */
|
||||
private void toggleTabLayoutArrows(int scrollX){
|
||||
// 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);
|
||||
|
||||
// TODO: hide right arrow when no need to scroll
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
|
@@ -16,7 +16,12 @@ import java.util.List;
|
||||
* Created by geoffroy on 15-11-27.
|
||||
* Data access class that handles Tasks
|
||||
*/
|
||||
public class TaskDataAccess {
|
||||
public class TaskDataAccess implements AutoCloseable {
|
||||
public enum MODE {
|
||||
READ,
|
||||
WRITE
|
||||
}
|
||||
|
||||
private SQLiteDatabase database;
|
||||
private DatabaseHelper dbHelper;
|
||||
private String[] taskColumns = {
|
||||
@@ -27,15 +32,21 @@ public class TaskDataAccess {
|
||||
private List<String> priorities = new ArrayList<>();
|
||||
|
||||
public TaskDataAccess(Context context) {
|
||||
this(context, MODE.READ);
|
||||
}
|
||||
public TaskDataAccess(Context context, MODE writeMode) {
|
||||
dbHelper = new DatabaseHelper(context);
|
||||
|
||||
priorities.add(context.getString(R.string.new_task_priority_low));
|
||||
priorities.add(context.getString(R.string.new_task_priority_normal));
|
||||
priorities.add(context.getString(R.string.new_task_priority_high));
|
||||
|
||||
open(writeMode);
|
||||
}
|
||||
|
||||
public void open() throws SQLException {
|
||||
database = dbHelper.getWritableDatabase();
|
||||
public void open(MODE writeMode) throws SQLException {
|
||||
if (writeMode == MODE.WRITE) database = dbHelper.getWritableDatabase();
|
||||
else database = dbHelper.getReadableDatabase();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@@ -48,7 +48,7 @@ public class TasksFragment extends Fragment implements
|
||||
|
||||
private static final String TASK_LIST_ID = "task_list_id";
|
||||
private long taskListId = -1;
|
||||
private TaskDataAccess taskDataAccess;
|
||||
//private TaskDataAccess taskDataAccess;
|
||||
private TaskRecyclerViewAdapter taskRecyclerViewAdapter;
|
||||
private View view;
|
||||
private RecyclerView recyclerView;
|
||||
@@ -86,8 +86,6 @@ public class TasksFragment extends Fragment implements
|
||||
view = inflater.inflate(R.layout.fragment_tasks, container, false);
|
||||
final Context context = view.getContext();
|
||||
|
||||
taskDataAccess = new TaskDataAccess(view.getContext());
|
||||
taskDataAccess.open();
|
||||
|
||||
// Set the Recycler view
|
||||
recyclerView = (RecyclerView) view.findViewById(R.id.task_list_view);
|
||||
@@ -95,9 +93,11 @@ public class TasksFragment extends Fragment implements
|
||||
|
||||
// Set RecyclerView Adapter
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
taskRecyclerViewAdapter = new TaskRecyclerViewAdapter(
|
||||
taskDataAccess.getAllTasks(taskListId),
|
||||
Integer.valueOf(sharedPref.getString("pref_conf_task_layout", "1")));
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext())) {
|
||||
taskRecyclerViewAdapter = new TaskRecyclerViewAdapter(
|
||||
taskDataAccess.getAllTasks(taskListId),
|
||||
Integer.valueOf(sharedPref.getString("pref_conf_task_layout", "1")));
|
||||
}
|
||||
recyclerView.setAdapter(taskRecyclerViewAdapter);
|
||||
|
||||
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
||||
@@ -166,16 +166,9 @@ public class TasksFragment extends Fragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (snackbar != null) snackbar.dismiss();
|
||||
taskDataAccess.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
taskDataAccess.open();
|
||||
}
|
||||
|
||||
/** Performs an action on a task: done, next or delete */
|
||||
@@ -236,21 +229,21 @@ 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)
|
||||
{
|
||||
// Mark item as Done
|
||||
case ItemTouchHelper.LEFT:
|
||||
taskDataAccess.setDone(itemId);
|
||||
break;
|
||||
// Increase task cycle count
|
||||
case ItemTouchHelper.RIGHT:
|
||||
taskDataAccess.increaseCycle(task.getCycle(), itemId);
|
||||
break;
|
||||
case -1:
|
||||
// Commit the changes to DB
|
||||
taskDataAccess.deleteTask(itemId);
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) {
|
||||
switch (direction) {
|
||||
// Mark item as Done
|
||||
case ItemTouchHelper.LEFT:
|
||||
taskDataAccess.setDone(itemId);
|
||||
break;
|
||||
// Increase task cycle count
|
||||
case ItemTouchHelper.RIGHT:
|
||||
taskDataAccess.increaseCycle(task.getCycle(), itemId);
|
||||
break;
|
||||
case -1:
|
||||
// Commit the changes to DB
|
||||
taskDataAccess.deleteTask(itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
@@ -308,34 +301,36 @@ public class TasksFragment extends Fragment implements
|
||||
TaskList taskList = (TaskList) listSpinner.getSelectedItem();
|
||||
|
||||
// Add the task to the database
|
||||
Task newTask = taskDataAccess.createOrUpdateTask(id,
|
||||
nameText.getText().toString(),
|
||||
descText.getText().toString(),
|
||||
priorityRadio.getText().toString(),
|
||||
taskList.getId());
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) {
|
||||
Task newTask = taskDataAccess.createOrUpdateTask(id,
|
||||
nameText.getText().toString(),
|
||||
descText.getText().toString(),
|
||||
priorityRadio.getText().toString(),
|
||||
taskList.getId());
|
||||
|
||||
Bundle args = dialog.getArguments();
|
||||
// Should never happen because we will have to be on this tab to open the dialog
|
||||
if (taskRecyclerViewAdapter == null) return;
|
||||
Bundle args = dialog.getArguments();
|
||||
// Should never happen because we will have to be on this tab to open the dialog
|
||||
if (taskRecyclerViewAdapter == null) return;
|
||||
|
||||
// Add the task
|
||||
if (task == null) {
|
||||
taskRecyclerViewAdapter.add(newTask, 0);
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
// Update the task
|
||||
else {
|
||||
int position = args.getInt("position");
|
||||
// Check if task list was changed
|
||||
if (task.getTaskListId() != taskList.getId())
|
||||
{
|
||||
// Remove item from current tab
|
||||
taskRecyclerViewAdapter.remove(position);
|
||||
//UpdateCycleCount();
|
||||
// Add the task
|
||||
if (task == null) {
|
||||
taskRecyclerViewAdapter.add(newTask, 0);
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
// Update the task
|
||||
else {
|
||||
int position = args.getInt("position");
|
||||
// Check if task list was changed
|
||||
if (task.getTaskListId() != taskList.getId())
|
||||
{
|
||||
// Remove item from current tab
|
||||
taskRecyclerViewAdapter.remove(position);
|
||||
//UpdateCycleCount();
|
||||
|
||||
// Add it to the corresponding tab provided it is already instanciated
|
||||
mAdapter.onTaskListChanged(newTask, listSpinner.getSelectedItemPosition());
|
||||
} else taskRecyclerViewAdapter.update(newTask, position);
|
||||
// Add it to the corresponding tab provided it is already instantiated
|
||||
mAdapter.onTaskListChanged(newTask, listSpinner.getSelectedItemPosition());
|
||||
} else taskRecyclerViewAdapter.update(newTask, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@@ -7,9 +7,14 @@
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.wismna.geoffroy.donext.activities.AboutActivity">
|
||||
<TextView
|
||||
android:id="@+id/version"
|
||||
android:id="@+id/version_donext"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
||||
<TextView
|
||||
android:id="@+id/version_android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
@@ -90,5 +90,6 @@
|
||||
<string name="title_activity_task_list">TaskListActivity</string>
|
||||
|
||||
<!-- Strings related to About -->
|
||||
<string name="about_version">Version %s</string>
|
||||
<string name="about_version_donext">DoNext version %s</string>
|
||||
<string name="about_version_android">Android version %s</string>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user