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.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
@@ -57,20 +56,35 @@ public class MainFragment extends Fragment implements
// Inflate the layout for this fragment
mView = inflater.inflate(R.layout.fragment_main, container, false);
Toolbar toolbar = mView.findViewById(R.id.toolbar);
AppCompatActivity activity = (AppCompatActivity) getActivity();
assert activity != null;
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
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;
}
@@ -113,29 +127,12 @@ public class MainFragment extends Fragment implements
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), taskLists);
mSectionsPagerAdapter.notifyDataSetChanged();
}
boolean isLargeLayout = getResources().getBoolean(R.bool.large_layout);
// No tasks, show the edit task lists fragment
if (taskLists.size() == 0) {
TaskListsDialogFragment taskListFragment = TaskListsDialogFragment.newInstance(this);
String title = getString(R.string.task_list_no_lists);
FragmentManager fragmentManager = activity.getSupportFragmentManager();
// Set the arguments
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));
}
// Otherwise, show the normal view
else {
// Set up the ViewPager with the sections adapter.
mViewPager = mView.findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
if (!isLargeLayout) {
if (!getResources().getBoolean(R.bool.large_layout)) {
tabLayout = mView.findViewById(R.id.tabs);
// Hide the tabs if there is only one task list
@@ -169,7 +166,6 @@ public class MainFragment extends Fragment implements
});
}
}
}
private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) {
TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position);

View File

@@ -107,6 +107,12 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
private void setTaskValues(Activity activity) {
// Populate spinner with task lists
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
ArrayAdapter<TaskList> adapter = new ArrayAdapter<>(
activity, android.R.layout.simple_spinner_item, taskLists);

View File

@@ -9,6 +9,11 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
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
android:id="@+id/version_donext"
android:layout_width="wrap_content"

View File

@@ -63,4 +63,6 @@
<string name="task_list_ok">OK</string>
<string name="title_activity_history">Historique</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>

View File

@@ -65,8 +65,10 @@
<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_max_lists_label">Maximum number of lists</string>
<string name="default_task_list_name">My tasks</string>
<!-- 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_android">Android version %d</string>
<string name="about_link" translatable="false">https://github.com/wismna</string>