mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Changes are now persisted when application is closed while the Snackbar is opened.
Edit list menu button is now outside the menu, with an icon New menu button to allow faster layout changing (does the same as going in the Settings) Current opened tab is now saved when re-opening app
This commit is contained in:
@@ -8,8 +8,8 @@ android {
|
|||||||
applicationId "com.wismna.geoffroy.donext"
|
applicationId "com.wismna.geoffroy.donext"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 23
|
targetSdkVersion 23
|
||||||
versionCode 6
|
versionCode 7
|
||||||
versionName "0.6"
|
versionName "0.7"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package com.wismna.geoffroy.donext.activities;
|
package com.wismna.geoffroy.donext.activities;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@@ -72,6 +74,10 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
// Set up the ViewPager with the sections adapter.
|
// Set up the ViewPager with the sections adapter.
|
||||||
mViewPager = (ViewPager) findViewById(R.id.container);
|
mViewPager = (ViewPager) findViewById(R.id.container);
|
||||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||||
|
// Open last opened tab
|
||||||
|
SharedPreferences sharedPref =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
||||||
|
mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0));
|
||||||
|
|
||||||
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||||
tabLayout.setupWithViewPager(mViewPager);
|
tabLayout.setupWithViewPager(mViewPager);
|
||||||
@@ -80,8 +86,36 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
fab.show();
|
fab.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
// Save currently opened tab
|
||||||
|
SharedPreferences sharedPref =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
||||||
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
|
editor.putInt("last_opened_tab", mViewPager.getCurrentItem());
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
|
MenuItem item = menu.findItem(R.id.action_changeLayout);
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
String layoutType = sharedPref.getString("pref_conf_task_layout", "1");
|
||||||
|
switch (layoutType) {
|
||||||
|
case "1" :
|
||||||
|
item.setIcon(R.drawable.ic_list_white_24dp);
|
||||||
|
break;
|
||||||
|
case "2" :
|
||||||
|
item.setIcon(R.drawable.ic_view_list_white_24dp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onPrepareOptionsMenu(menu);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
@@ -122,17 +156,33 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
|||||||
taskDialogFragment.show(manager, "Create new task");
|
taskDialogFragment.show(manager, "Create new task");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when the user clicks the Settings button */
|
/** Called when the user clicks on the Change Layout button */
|
||||||
public void openSettings(MenuItem menuItem) {
|
public void changeLayout(MenuItem item) {
|
||||||
Intent intent = new Intent(this, SettingsActivity.class);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
startActivity(intent);
|
SharedPreferences.Editor editor = sharedPref.edit();
|
||||||
|
String layoutTypeString = sharedPref.getString("pref_conf_task_layout", "1");
|
||||||
|
int layoutType = Integer.valueOf(layoutTypeString);
|
||||||
|
editor.putString("pref_conf_task_layout", String.valueOf(layoutType % 2 + 1));
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
// Update the ViewPagerAdapter to refresh all tabs
|
||||||
|
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||||
|
// Invalidate the menu to redraw the icon
|
||||||
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Called when the user clicks the Edit Lists button */
|
/** Called when the user clicks the Edit Lists button */
|
||||||
public void openTaskLists(MenuItem menuItem) {
|
public void openTaskLists(MenuItem menuItem) {
|
||||||
Intent intent = new Intent(this, TaskListActivity.class);
|
Intent intent = new Intent(this, TaskListActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called when the user clicks the Settings button */
|
||||||
|
public void openSettings(MenuItem menuItem) {
|
||||||
|
Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) {
|
private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) {
|
||||||
TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position);
|
TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position);
|
||||||
if (taskFragment == null) return null;
|
if (taskFragment == null) return null;
|
||||||
|
@@ -21,6 +21,11 @@ public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerA
|
|||||||
super(fragmentManager);
|
super(fragmentManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemPosition(Object object) {
|
||||||
|
return POSITION_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
// Register the fragment when the item is instantiated
|
// Register the fragment when the item is instantiated
|
||||||
@Override
|
@Override
|
||||||
public Object instantiateItem(ViewGroup container, int position) {
|
public Object instantiateItem(ViewGroup container, int position) {
|
||||||
|
@@ -52,6 +52,7 @@ public class TasksFragment extends Fragment implements
|
|||||||
private View view;
|
private View view;
|
||||||
private RecyclerView recyclerView;
|
private RecyclerView recyclerView;
|
||||||
private TaskChangedAdapter mAdapter;
|
private TaskChangedAdapter mAdapter;
|
||||||
|
private Snackbar snackbar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||||
@@ -164,6 +165,7 @@ public class TasksFragment extends Fragment implements
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
if (snackbar != null) snackbar.dismiss();
|
||||||
taskDataAccess.close();
|
taskDataAccess.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +200,7 @@ public class TasksFragment extends Fragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup the snack bar
|
// Setup the snack bar
|
||||||
Snackbar.make(view, "Task " + action, Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(view, "Task " + action, Snackbar.LENGTH_LONG)
|
||||||
.setAction("Undo", new View.OnClickListener() {
|
.setAction("Undo", new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -220,7 +222,8 @@ public class TasksFragment extends Fragment implements
|
|||||||
taskRecyclerViewAdapter.add(task, itemPosition);
|
taskRecyclerViewAdapter.add(task, itemPosition);
|
||||||
recyclerView.scrollToPosition(0);
|
recyclerView.scrollToPosition(0);
|
||||||
}
|
}
|
||||||
}).setCallback(new Snackbar.Callback() {
|
});
|
||||||
|
snackbar.setCallback(new Snackbar.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDismissed(Snackbar snackbar, int event) {
|
public void onDismissed(Snackbar snackbar, int event) {
|
||||||
super.onDismissed(snackbar, event);
|
super.onDismissed(snackbar, event);
|
||||||
@@ -243,8 +246,6 @@ public class TasksFragment extends Fragment implements
|
|||||||
// Commit the changes to DB
|
// Commit the changes to DB
|
||||||
taskDataAccess.deleteTask(itemId);
|
taskDataAccess.deleteTask(itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//UpdateCycleCount();
|
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,8 @@
|
|||||||
<android.support.design.widget.TabLayout
|
<android.support.design.widget.TabLayout
|
||||||
android:id="@+id/tabs"
|
android:id="@+id/tabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
app:tabMode="scrollable" />
|
||||||
|
|
||||||
</android.support.design.widget.AppBarLayout>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
|
@@ -9,11 +9,19 @@
|
|||||||
android:onClick="openNewTaskDialog"
|
android:onClick="openNewTaskDialog"
|
||||||
app:showAsAction="never" />-->
|
app:showAsAction="never" />-->
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_editTabs"
|
android:id="@+id/action_changeLayout"
|
||||||
android:orderInCategory="20"
|
android:orderInCategory="20"
|
||||||
|
android:title="@string/action_changeLayout"
|
||||||
|
android:onClick="changeLayout"
|
||||||
|
android:icon="@drawable/ic_view_list_white_24dp"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_editTabs"
|
||||||
|
android:orderInCategory="25"
|
||||||
android:title="@string/action_editTabs"
|
android:title="@string/action_editTabs"
|
||||||
android:onClick="openTaskLists"
|
android:onClick="openTaskLists"
|
||||||
app:showAsAction="never" />
|
android:icon="@drawable/ic_create_new_folder_white_24dp"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_settings"
|
android:id="@+id/action_settings"
|
||||||
android:orderInCategory="30"
|
android:orderInCategory="30"
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
<string name="action_editTabs">Edit lists</string>
|
<string name="action_editTabs">Edit lists</string>
|
||||||
<string name="action_about">About</string>
|
<string name="action_about">About</string>
|
||||||
<string name="action_new_task">New task</string>
|
<string name="action_new_task">New task</string>
|
||||||
|
<string name="action_changeLayout">Change layout</string>
|
||||||
<string name="settings_activity_title">Settings</string>
|
<string name="settings_activity_title">Settings</string>
|
||||||
|
|
||||||
<!-- Strings related to Task List edition -->
|
<!-- Strings related to Task List edition -->
|
||||||
|
Reference in New Issue
Block a user