Fragments rotation bugs correction

New task layout for large screens (tablets)
Better task list layout
This commit is contained in:
bg45
2017-02-28 17:24:36 -05:00
parent e3c02c54d4
commit 558a0dad02
9 changed files with 135 additions and 34 deletions

View File

@@ -5,7 +5,7 @@
<GradleProjectSettings> <GradleProjectSettings>
<option name="distributionType" value="LOCAL" /> <option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.14.1" /> <option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.14.1" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

View File

@@ -8,8 +8,8 @@ android {
applicationId "com.wismna.geoffroy.donext" applicationId "com.wismna.geoffroy.donext"
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 25 targetSdkVersion 25
versionCode 12 versionCode 13
versionName "1.1.0" versionName "1.2.0"
} }
buildTypes { buildTypes {
release { release {
@@ -22,10 +22,10 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.1' compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.1.1' compile 'com.android.support:design:25.2.0'
compile 'com.android.support:support-v4:25.1.1' compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:percent:25.1.1' compile 'com.android.support:percent:25.2.0'
compile 'com.android.support:recyclerview-v7:25.1.1' compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.google.android.gms:play-services-ads:10.0.1' compile 'com.google.android.gms:play-services-ads:10.2.0'
} }

View File

@@ -18,6 +18,10 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.wismna.geoffroy.donext.R; import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.adapters.SmartFragmentStatePagerAdapter; import com.wismna.geoffroy.donext.adapters.SmartFragmentStatePagerAdapter;
@@ -82,7 +86,9 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
PreferenceManager.getDefaultSharedPreferences(MainActivity.this); PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0)); mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0));
tabLayout = (TabLayout) findViewById(R.id.tabs); View tabs = findViewById(R.id.tabs);
if (tabs instanceof TabLayout) {
tabLayout = (TabLayout) tabs;
tabLayout.setupWithViewPager(mViewPager); tabLayout.setupWithViewPager(mViewPager);
// Handles scroll detection (only available for SDK version >=23) // Handles scroll detection (only available for SDK version >=23)
@@ -96,7 +102,18 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
} }
}); });
} }
}
else if (tabs instanceof ListView) {
ListView listView = (ListView) tabs;
listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskLists));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mViewPager.setCurrentItem(position);
view.setSelected(true);
}
});
}
// Hide or show new task floating button // Hide or show new task floating button
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.show(); fab.show();
@@ -221,17 +238,20 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
private void toggleTabLayoutArrows(int scrollX){ private void toggleTabLayoutArrows(int scrollX){
// Hide left arrow when scrolled to the left // Hide left arrow when scrolled to the left
View leftArrow = findViewById(R.id.left_arrow); View leftArrow = findViewById(R.id.left_arrow);
if (leftArrow != null) {
if (scrollX <= 1) leftArrow.setVisibility(View.INVISIBLE); if (scrollX <= 1) leftArrow.setVisibility(View.INVISIBLE);
else leftArrow.setVisibility(View.VISIBLE); else leftArrow.setVisibility(View.VISIBLE);
}
// Hide right arrow when scrolled to the right // Hide right arrow when scrolled to the right
View rightArrow = findViewById(R.id.right_arrow); View rightArrow = findViewById(R.id.right_arrow);
if (rightArrow != null) {
Point size = new Point(); Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size); getWindowManager().getDefaultDisplay().getSize(size);
if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - tabLayout.getMeasuredWidth()) if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - tabLayout.getMeasuredWidth())
rightArrow.setVisibility(View.INVISIBLE); rightArrow.setVisibility(View.INVISIBLE);
else rightArrow.setVisibility(View.VISIBLE); else rightArrow.setVisibility(View.VISIBLE);
} }
}
/** /**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to * A {@link FragmentPagerAdapter} that returns a fragment corresponding to

View File

@@ -28,6 +28,7 @@ public class ConfirmDialogFragment extends DialogFragment {
ConfirmDialogFragment fragment = new ConfirmDialogFragment(); ConfirmDialogFragment fragment = new ConfirmDialogFragment();
//fragment.message = message; //fragment.message = message;
fragment.confirmDialogListener = confirmDialogListener; fragment.confirmDialogListener = confirmDialogListener;
fragment.setRetainInstance(true);
return fragment; return fragment;
} }
@@ -70,4 +71,15 @@ public class ConfirmDialogFragment extends DialogFragment {
dialog.setCanceledOnTouchOutside(true); dialog.setCanceledOnTouchOutside(true);
return dialog; return dialog;
} }
@Override
public void onDestroyView() {
Dialog dialog = getDialog();
// Stop the dialog from being dismissed on rotation, due to a bug with the compatibility library
// https://code.google.com/p/android/issues/detail?id=17423
if (dialog != null && getRetainInstance()) {
dialog.setDismissMessage(null);
}
super.onDestroyView();
}
} }

View File

@@ -51,7 +51,6 @@ public class TaskDialogFragment extends DialogFragment {
fragment.task = task; fragment.task = task;
fragment.taskLists = taskLists; fragment.taskLists = taskLists;
fragment.mListener = newTaskListener; fragment.mListener = newTaskListener;
// TODO: keep dialog open when rotating
fragment.setRetainInstance(true); fragment.setRetainInstance(true);
return fragment; return fragment;
} }
@@ -147,4 +146,15 @@ public class TaskDialogFragment extends DialogFragment {
}); });
} }
} }
@Override
public void onDestroyView() {
Dialog dialog = getDialog();
// Stop the dialog from being dismissed on rotation, due to a bug with the compatibility library
// https://code.google.com/p/android/issues/detail?id=17423
if (dialog != null && getRetainInstance()) {
dialog.setDismissMessage(null);
}
super.onDestroyView();
}
} }

View File

@@ -1,5 +1,6 @@
package com.wismna.geoffroy.donext.fragments; package com.wismna.geoffroy.donext.fragments;
import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@@ -68,6 +69,7 @@ public class TasksFragment extends Fragment implements
args.putLong(TASK_LIST_ID, taskListId); args.putLong(TASK_LIST_ID, taskListId);
fragment.setArguments(args); fragment.setArguments(args);
fragment.mAdapter = taskChangedAdapter; fragment.mAdapter = taskChangedAdapter;
fragment.setRetainInstance(true);
return fragment; return fragment;
} }
@@ -80,6 +82,7 @@ public class TasksFragment extends Fragment implements
} }
} }
@SuppressLint("NewApi")
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@@ -221,7 +224,8 @@ public class TasksFragment extends Fragment implements
recyclerView.scrollToPosition(0); recyclerView.scrollToPosition(0);
} }
}); });
snackbar.setCallback(new Snackbar.Callback() { snackbar.addCallback(new Snackbar.Callback() {
@SuppressLint("NewApi")
@Override @Override
public void onDismissed(Snackbar snackbar, int event) { public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event); super.onDismissed(snackbar, event);
@@ -284,6 +288,7 @@ public class TasksFragment extends Fragment implements
} }
} }
@SuppressLint("NewApi")
@Override @Override
public void onNewTaskDialogPositiveClick(DialogFragment dialog) { public void onNewTaskDialogPositiveClick(DialogFragment dialog) {
// Get the dialog fragment // Get the dialog fragment

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:onClick="onNewTaskClick"
android:src="@drawable/ic_add_white_24dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="80dp"
android:orientation="horizontal">
<android.widget.ListView
android:id="@+id/tabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"/>
<com.wismna.geoffroy.donext.widgets.NonSwipeableViewPager
android:id="@+id/container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <ImageView
@@ -19,8 +19,9 @@
android:textAppearance="?android:attr/textAppearanceMedium"/> android:textAppearance="?android:attr/textAppearanceMedium"/>
<EditText <EditText
android:id="@+id/task_list_name" android:id="@+id/task_list_name"
android:layout_width="175dp" android:layout_width="0dp"
android:layout_height="?listPreferredItemHeight" android:layout_height="?listPreferredItemHeight"
android:layout_weight="2"
android:inputType="text" android:inputType="text"
android:textAppearance="?android:attr/textAppearanceLarge"/> android:textAppearance="?android:attr/textAppearanceLarge"/>
<Button <Button

View File

@@ -20,8 +20,9 @@
android:layout_marginStart="75dp"> android:layout_marginStart="75dp">
<EditText <EditText
android:id="@+id/new_task_list_name" android:id="@+id/new_task_list_name"
android:layout_width="175dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="@string/task_list_new_list_hint"/> android:hint="@string/task_list_new_list_hint"/>
<Button <Button
android:id="@+id/new_task_list_button" android:id="@+id/new_task_list_button"