Create a default task list on first app launch

Hide spinner in task dialog fragment when only one task list
Added some text in About
This commit is contained in:
BONNEVILLE Geoffroy
2017-12-22 17:26:08 +01:00
parent e5c150aaf5
commit 59e1165c89
5 changed files with 65 additions and 54 deletions

View File

@@ -9,7 +9,6 @@ import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@@ -57,20 +56,35 @@ public class MainFragment extends Fragment implements
// Inflate the layout for this fragment // Inflate the layout for this fragment
mView = inflater.inflate(R.layout.fragment_main, container, false); mView = inflater.inflate(R.layout.fragment_main, container, false);
Toolbar toolbar = mView.findViewById(R.id.toolbar); Toolbar toolbar = mView.findViewById(R.id.toolbar);
AppCompatActivity activity = (AppCompatActivity) getActivity(); AppCompatActivity activity = (AppCompatActivity) getActivity();
assert activity != null; assert activity != null;
activity.setSupportActionBar(toolbar); activity.setSupportActionBar(toolbar);
// TODO: determine whether this is the first startup, and if so, show a tutorial of sorts // Get preferences
SharedPreferences sharedPref =
PreferenceManager.getDefaultSharedPreferences(activity);
// Check if this is the first time loading this app
boolean first_time = sharedPref.getBoolean("first_time", true);
// If it is, create a default task list
if (first_time) {
try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(activity)) {
taskListDataAccess.createTaskList(getString(R.string.default_task_list_name), 0);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("first_time", false);
editor.apply();
}
}
// Load task lists // Load task lists
updateTaskLists(activity); updateTaskLists(activity);
SharedPreferences sharedPref =
PreferenceManager.getDefaultSharedPreferences(activity);
int lastOpenedList = sharedPref.getInt("last_opened_tab", 0);
// Open last opened tab
mViewPager.setCurrentItem(lastOpenedList);
if (!first_time) {
// Open last opened tab
int lastOpenedList = sharedPref.getInt("last_opened_tab", 0);
mViewPager.setCurrentItem(lastOpenedList);
}
return mView; return mView;
} }
@@ -113,62 +127,44 @@ public class MainFragment extends Fragment implements
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), taskLists); mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), taskLists);
mSectionsPagerAdapter.notifyDataSetChanged(); mSectionsPagerAdapter.notifyDataSetChanged();
} }
boolean isLargeLayout = getResources().getBoolean(R.bool.large_layout);
// No tasks, show the edit task lists fragment // Set up the ViewPager with the sections adapter.
if (taskLists.size() == 0) { mViewPager = mView.findViewById(R.id.container);
TaskListsDialogFragment taskListFragment = TaskListsDialogFragment.newInstance(this); mViewPager.setAdapter(mSectionsPagerAdapter);
String title = getString(R.string.task_list_no_lists);
FragmentManager fragmentManager = activity.getSupportFragmentManager();
// Set the arguments if (!getResources().getBoolean(R.bool.large_layout)) {
Bundle args = new Bundle();
args.putInt("button_count", 1);
args.putString("button_negative", getString(R.string.task_list_ok));
taskListFragment.setArguments(args);
taskListFragment.showFragment(fragmentManager, title, getResources().getBoolean(R.bool.large_layout)); tabLayout = mView.findViewById(R.id.tabs);
} // Hide the tabs if there is only one task list
// Otherwise, show the normal view tabLayout.setVisibility(taskLists.size() == 1 && !isHistoryActivity ? View.GONE : View.VISIBLE);
else { tabLayout.setupWithViewPager(mViewPager);
// Set up the ViewPager with the sections adapter.
mViewPager = mView.findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
if (!isLargeLayout) { // Handles scroll detection (only available for SDK version >=23)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tabLayout = mView.findViewById(R.id.tabs); toggleTabLayoutArrows(tabLayout.getScrollX());
// Hide the tabs if there is only one task list //tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT);
tabLayout.setVisibility(taskLists.size() == 1 && !isHistoryActivity ? View.GONE : View.VISIBLE); tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() {
tabLayout.setupWithViewPager(mViewPager);
// Handles scroll detection (only available for SDK version >=23)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
toggleTabLayoutArrows(tabLayout.getScrollX());
//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);
}
});
}
}
else {
ListView listView = mView.findViewById(R.id.list);
// Hide the list if there is only one task list
listView.setVisibility(taskLists.size() == 1 && !isHistoryActivity ? View.GONE : View.VISIBLE);
//listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskLists));
listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists));
//listView.setSelection(lastOpenedList);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
mViewPager.setCurrentItem(position); toggleTabLayoutArrows(scrollX);
} }
}); });
} }
} }
else {
ListView listView = mView.findViewById(R.id.list);
// Hide the list if there is only one task list
listView.setVisibility(taskLists.size() == 1 && !isHistoryActivity ? View.GONE : View.VISIBLE);
//listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskLists));
listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists));
//listView.setSelection(lastOpenedList);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mViewPager.setCurrentItem(position);
}
});
}
} }
private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) { private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) {

View File

@@ -107,6 +107,12 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
private void setTaskValues(Activity activity) { private void setTaskValues(Activity activity) {
// Populate spinner with task lists // Populate spinner with task lists
Spinner spinner = findViewById(R.id.new_task_list); Spinner spinner = findViewById(R.id.new_task_list);
// Hide spinner if only one task list
if (taskLists.size() <= 1) {
spinner.setVisibility(View.GONE);
TextView taskListLabel = findViewById(R.id.new_task_list_label);
taskListLabel.setVisibility(View.GONE);
}
// Create an ArrayAdapter using the string array and a default spinner layout // Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<TaskList> adapter = new ArrayAdapter<>( ArrayAdapter<TaskList> adapter = new ArrayAdapter<>(
activity, android.R.layout.simple_spinner_item, taskLists); activity, android.R.layout.simple_spinner_item, taskLists);

View File

@@ -9,6 +9,11 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical" android:orientation="vertical"
tools:context=".activities.AboutActivity"> tools:context=".activities.AboutActivity">
<TextView
android:id="@+id/description_donext"
android:text="@string/donext_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView <TextView
android:id="@+id/version_donext" android:id="@+id/version_donext"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -63,4 +63,6 @@
<string name="task_list_ok">OK</string> <string name="task_list_ok">OK</string>
<string name="title_activity_history">Historique</string> <string name="title_activity_history">Historique</string>
<string name="action_view_task">Tâche</string> <string name="action_view_task">Tâche</string>
<string name="donext_description">DoNext est un nouveau genre de gestionnaire de tâches, basé sur le principe que créer trop de tâches est contre-productif. Faites plutôt glisser vos tâches vers la gauche ou la droite pour les mettre à la fin de votre liste et travailler dessus plus tard !</string>
<string name="default_task_list_name">Mes tâches</string>
</resources> </resources>

View File

@@ -65,8 +65,10 @@
<string name="settings_today_enable">Enable Today view?</string> <string name="settings_today_enable">Enable Today view?</string>
<string name="settings_today_desc">The Today view is a special way of showing your tasks. Select which tasks you want to do during the day and they will show up in this view. At the end of the day, the view is reset.</string> <string name="settings_today_desc">The Today view is a special way of showing your tasks. Select which tasks you want to do during the day and they will show up in this view. At the end of the day, the view is reset.</string>
<string name="settings_max_lists_label">Maximum number of lists</string> <string name="settings_max_lists_label">Maximum number of lists</string>
<string name="default_task_list_name">My tasks</string>
<!-- Strings related to About --> <!-- Strings related to About -->
<string name="donext_description">DoNext is a new kind of task manager, based on the premise that creating too many tasks is counterproductive. Instead, swipe tasks left and right to push them back to the bottom of your backlog to work on them at a later time!</string>
<string name="about_version_donext">DoNext version %s</string> <string name="about_version_donext">DoNext version %s</string>
<string name="about_version_android">Android version %d</string> <string name="about_version_android">Android version %d</string>
<string name="about_link" translatable="false">https://github.com/wismna</string> <string name="about_link" translatable="false">https://github.com/wismna</string>