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:
2016-01-15 13:38:24 -05:00
committed by geoffroy
parent 2c1fad07aa
commit dd67ff4421
7 changed files with 101 additions and 35 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.wismna.geoffroy.donext"
minSdkVersion 15
targetSdkVersion 23
versionCode 6
versionName "0.6"
versionCode 7
versionName "0.7"
}
buildTypes {
release {

View File

@@ -1,7 +1,9 @@
package com.wismna.geoffroy.donext.activities;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
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.
mViewPager = (ViewPager) findViewById(R.id.container);
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.setupWithViewPager(mViewPager);
@@ -80,8 +86,36 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
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
public boolean onCreateOptionsMenu(Menu menu) {
// 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");
}
/** Called when the user clicks the Settings button */
public void openSettings(MenuItem menuItem) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
/** Called when the user clicks on the Change Layout button */
public void changeLayout(MenuItem item) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
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 */
public void openTaskLists(MenuItem menuItem) {
Intent intent = new Intent(this, TaskListActivity.class);
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) {
TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position);
if (taskFragment == null) return null;

View File

@@ -21,6 +21,11 @@ public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerA
super(fragmentManager);
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
// Register the fragment when the item is instantiated
@Override
public Object instantiateItem(ViewGroup container, int position) {

View File

@@ -52,6 +52,7 @@ public class TasksFragment extends Fragment implements
private View view;
private RecyclerView recyclerView;
private TaskChangedAdapter mAdapter;
private Snackbar snackbar;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
@@ -164,6 +165,7 @@ public class TasksFragment extends Fragment implements
@Override
public void onDestroy() {
super.onDestroy();
if (snackbar != null) snackbar.dismiss();
taskDataAccess.close();
}
@@ -198,7 +200,7 @@ public class TasksFragment extends Fragment implements
}
// 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() {
@Override
public void onClick(View v) {
@@ -220,7 +222,8 @@ public class TasksFragment extends Fragment implements
taskRecyclerViewAdapter.add(task, itemPosition);
recyclerView.scrollToPosition(0);
}
}).setCallback(new Snackbar.Callback() {
});
snackbar.setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
@@ -243,8 +246,6 @@ public class TasksFragment extends Fragment implements
// Commit the changes to DB
taskDataAccess.deleteTask(itemId);
}
//UpdateCycleCount();
}
}).show();
}

View File

@@ -26,7 +26,8 @@
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>

View File

@@ -9,11 +9,19 @@
android:onClick="openNewTaskDialog"
app:showAsAction="never" />-->
<item
android:id="@+id/action_editTabs"
android:id="@+id/action_changeLayout"
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:onClick="openTaskLists"
app:showAsAction="never" />
android:icon="@drawable/ic_create_new_folder_white_24dp"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"
android:orderInCategory="30"

View File

@@ -6,6 +6,7 @@
<string name="action_editTabs">Edit lists</string>
<string name="action_about">About</string>
<string name="action_new_task">New task</string>
<string name="action_changeLayout">Change layout</string>
<string name="settings_activity_title">Settings</string>
<!-- Strings related to Task List edition -->