mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Fragments rotation bugs correction
New task layout for large screens (tablets) Better task list layout
This commit is contained in:
2
DoNExt/.idea/gradle.xml
generated
2
DoNExt/.idea/gradle.xml
generated
@@ -5,7 +5,7 @@
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="LOCAL" />
|
||||
<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">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "com.wismna.geoffroy.donext"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 25
|
||||
versionCode 12
|
||||
versionName "1.1.0"
|
||||
versionCode 13
|
||||
versionName "1.2.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@@ -22,10 +22,10 @@ android {
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:25.1.1'
|
||||
compile 'com.android.support:design:25.1.1'
|
||||
compile 'com.android.support:support-v4:25.1.1'
|
||||
compile 'com.android.support:percent:25.1.1'
|
||||
compile 'com.android.support:recyclerview-v7:25.1.1'
|
||||
compile 'com.google.android.gms:play-services-ads:10.0.1'
|
||||
compile 'com.android.support:appcompat-v7:25.2.0'
|
||||
compile 'com.android.support:design:25.2.0'
|
||||
compile 'com.android.support:support-v4:25.2.0'
|
||||
compile 'com.android.support:percent:25.2.0'
|
||||
compile 'com.android.support:recyclerview-v7:25.2.0'
|
||||
compile 'com.google.android.gms:play-services-ads:10.2.0'
|
||||
}
|
||||
|
@@ -18,6 +18,10 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
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.adapters.SmartFragmentStatePagerAdapter;
|
||||
@@ -45,7 +49,7 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
private TabLayout tabLayout;
|
||||
private TabLayout tabLayout;
|
||||
private List<TaskList> taskLists;
|
||||
|
||||
@Override
|
||||
@@ -82,21 +86,34 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
||||
PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
|
||||
mViewPager.setCurrentItem(sharedPref.getInt("last_opened_tab", 0));
|
||||
|
||||
tabLayout = (TabLayout) findViewById(R.id.tabs);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
View tabs = findViewById(R.id.tabs);
|
||||
if (tabs instanceof TabLayout) {
|
||||
tabLayout = (TabLayout) tabs;
|
||||
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() {
|
||||
// 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 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 onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
toggleTabLayoutArrows(scrollX);
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mViewPager.setCurrentItem(position);
|
||||
view.setSelected(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Hide or show new task floating button
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.show();
|
||||
@@ -221,16 +238,19 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
|
||||
private void toggleTabLayoutArrows(int scrollX){
|
||||
// Hide left arrow when scrolled to the left
|
||||
View leftArrow = findViewById(R.id.left_arrow);
|
||||
if (scrollX <= 1) leftArrow.setVisibility(View.INVISIBLE);
|
||||
else leftArrow.setVisibility(View.VISIBLE);
|
||||
|
||||
if (leftArrow != null) {
|
||||
if (scrollX <= 1) leftArrow.setVisibility(View.INVISIBLE);
|
||||
else leftArrow.setVisibility(View.VISIBLE);
|
||||
}
|
||||
// Hide right arrow when scrolled to the right
|
||||
View rightArrow = findViewById(R.id.right_arrow);
|
||||
Point size = new Point();
|
||||
getWindowManager().getDefaultDisplay().getSize(size);
|
||||
if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - tabLayout.getMeasuredWidth())
|
||||
rightArrow.setVisibility(View.INVISIBLE);
|
||||
else rightArrow.setVisibility(View.VISIBLE);
|
||||
if (rightArrow != null) {
|
||||
Point size = new Point();
|
||||
getWindowManager().getDefaultDisplay().getSize(size);
|
||||
if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - tabLayout.getMeasuredWidth())
|
||||
rightArrow.setVisibility(View.INVISIBLE);
|
||||
else rightArrow.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,6 +28,7 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
ConfirmDialogFragment fragment = new ConfirmDialogFragment();
|
||||
//fragment.message = message;
|
||||
fragment.confirmDialogListener = confirmDialogListener;
|
||||
fragment.setRetainInstance(true);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@@ -70,4 +71,15 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@@ -51,7 +51,6 @@ public class TaskDialogFragment extends DialogFragment {
|
||||
fragment.task = task;
|
||||
fragment.taskLists = taskLists;
|
||||
fragment.mListener = newTaskListener;
|
||||
// TODO: keep dialog open when rotating
|
||||
fragment.setRetainInstance(true);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -68,6 +69,7 @@ public class TasksFragment extends Fragment implements
|
||||
args.putLong(TASK_LIST_ID, taskListId);
|
||||
fragment.setArguments(args);
|
||||
fragment.mAdapter = taskChangedAdapter;
|
||||
fragment.setRetainInstance(true);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@@ -80,6 +82,7 @@ public class TasksFragment extends Fragment implements
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@@ -221,7 +224,8 @@ public class TasksFragment extends Fragment implements
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
});
|
||||
snackbar.setCallback(new Snackbar.Callback() {
|
||||
snackbar.addCallback(new Snackbar.Callback() {
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onDismissed(Snackbar snackbar, int event) {
|
||||
super.onDismissed(snackbar, event);
|
||||
@@ -284,6 +288,7 @@ public class TasksFragment extends Fragment implements
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void onNewTaskDialogPositiveClick(DialogFragment dialog) {
|
||||
// Get the dialog fragment
|
||||
|
52
DoNExt/app/src/main/res/layout-large/activity_main.xml
Normal file
52
DoNExt/app/src/main/res/layout-large/activity_main.xml
Normal 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>
|
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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:orientation="horizontal" >
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:id="@+id/handle"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -19,8 +19,9 @@
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
<EditText
|
||||
android:id="@+id/task_list_name"
|
||||
android:layout_width="175dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="?listPreferredItemHeight"
|
||||
android:layout_weight="2"
|
||||
android:inputType="text"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
<Button
|
||||
|
@@ -20,8 +20,9 @@
|
||||
android:layout_marginStart="75dp">
|
||||
<EditText
|
||||
android:id="@+id/new_task_list_name"
|
||||
android:layout_width="175dp"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:hint="@string/task_list_new_list_hint"/>
|
||||
<Button
|
||||
android:id="@+id/new_task_list_button"
|
||||
|
Reference in New Issue
Block a user