Add action bar and persist split

This commit is contained in:
PavelRatushnyi 2017-09-05 03:33:08 +03:00
parent dd292b3688
commit 91cfaa600c
4 changed files with 64 additions and 80 deletions

View file

@ -11,21 +11,26 @@
android:id="@+id/split_interval_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
android:background="@color/osmand_orange"
android:minHeight="@dimen/dashboard_map_toolbar"
android:theme="?attr/toolbar_theme"
android:theme="?attr/actionBarStyle"
app:contentInsetLeft="54dp"
app:contentInsetStart="54dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
tools:text="2017-02-16"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size_large"/>
tools:text="2017-02-16"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible"
android:indeterminate="true"/>
</android.support.v7.widget.Toolbar>

View file

@ -30,7 +30,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.SplitSegmentFragment;
import net.osmand.plus.myplaces.SplitSegmentDialogFragment;
import net.osmand.plus.myplaces.TrackPointFragment;
import net.osmand.plus.myplaces.TrackSegmentFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
@ -61,10 +61,6 @@ public class TrackActivity extends TabActivity {
private boolean openPointsTab = false;
private boolean openTracksList = false;
public PagerSlidingTabStrip getSlidingTabLayout() {
return slidingTabLayout;
}
@Override
public void onCreate(Bundle icicle) {
this.app = getMyApplication();
@ -294,8 +290,8 @@ public class TrackActivity extends TabActivity {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateContent();
} else if (frag instanceof SplitSegmentFragment) {
((SplitSegmentFragment) frag).reloadSplitFragment();
} else if (frag instanceof SplitSegmentDialogFragment) {
((SplitSegmentDialogFragment) frag).updateContent();
} else if (frag instanceof TrackPointFragment) {
((TrackPointFragment) frag).setContent();
}
@ -348,23 +344,6 @@ public class TrackActivity extends TabActivity {
int itemId = item.getItemId();
switch (itemId) {
case android.R.id.home:
int backStackEntriesCount = getSupportFragmentManager().getBackStackEntryCount();
if (backStackEntriesCount > 0) {
FragmentManager.BackStackEntry backStackEntry = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1);
if (backStackEntry.getName().equals(SplitSegmentFragment.TAG)) {
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateSplitView();
}
}
getSupportFragmentManager().popBackStack();
if (isHavingWayPoints() || isHavingRoutePoints()) {
getSlidingTabLayout().setVisibility(View.VISIBLE);
}
return true;
}
}
if (getIntent().hasExtra(MapActivity.INTENT_KEY_PARENT_MAP_ACTIVITY) || openTracksList) {
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
final Intent favorites = new Intent(this, appCustomization.getFavoritesActivity());
@ -379,25 +358,17 @@ public class TrackActivity extends TabActivity {
return false;
}
@Override
public void onBackPressed() {
int backStackEntriesCount = getSupportFragmentManager().getBackStackEntryCount();
if (backStackEntriesCount > 0) {
FragmentManager.BackStackEntry backStackEntry = getSupportFragmentManager().getBackStackEntryAt(getSupportFragmentManager().getBackStackEntryCount() - 1);
if (backStackEntry.getName().equals(SplitSegmentFragment.TAG)) {
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateSplitView();
}
}
getSupportFragmentManager().popBackStack();
if (isHavingWayPoints() || isHavingRoutePoints()) {
getSlidingTabLayout().setVisibility(View.VISIBLE);
}
return;
public void updateSplitView() {
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
if (frag instanceof TrackSegmentFragment) {
((TrackSegmentFragment) frag).updateSplitView();
}
}
}
@Override
public void onBackPressed() {
if (openTracksList) {
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
final Intent favorites = new Intent(this, appCustomization.getFavoritesActivity());

View file

@ -1,5 +1,6 @@
package net.osmand.plus.myplaces;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.graphics.Paint;
import android.graphics.Rect;
@ -8,13 +9,12 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.ListPopupWindow;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
@ -22,6 +22,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.AndroidUtils;
@ -51,9 +52,9 @@ import gnu.trove.list.array.TIntArrayList;
import static net.osmand.plus.myplaces.TrackSegmentFragment.ARG_TO_FILTER_SHORT_TRACKS;
public class SplitSegmentFragment extends DialogFragment {
public class SplitSegmentDialogFragment extends DialogFragment {
public final static String TAG = "SPLIT_SEGMENT_FRAGMENT";
public final static String TAG = "SPLIT_SEGMENT_DIALOG_FRAGMENT";
private OsmandApplication app;
private SplitSegmentsAdapter adapter;
@ -69,6 +70,7 @@ public class SplitSegmentFragment extends DialogFragment {
private Paint minMaxSpeedPaint;
private Rect minMaxSpeedTextBounds;
private ListView listView;
private ProgressBar progressBar;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
@ -89,12 +91,6 @@ public class SplitSegmentFragment extends DialogFragment {
getTrackActivity().onAttachFragment(this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
getTrackActivity().getClearToolbar(false);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
minMaxSpeedPaint = new Paint();
@ -106,6 +102,16 @@ public class SplitSegmentFragment extends DialogFragment {
final View view = getActivity().getLayoutInflater().inflate(R.layout.split_segments_layout, container, false);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.split_interval_toolbar);
TextView titleTextView = (TextView) toolbar.findViewById(R.id.title);
if (app.getSettings().isLightContent()) {
titleTextView.setTextAppearance(getContext(), R.style.Widget_Styled_LightActionBarHeader);
} else {
titleTextView.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
}
ActionBar trackActivityActionBar = getTrackActivity().getSupportActionBar();
if (trackActivityActionBar != null) {
titleTextView.setText(trackActivityActionBar.getTitle());
}
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
@ -114,6 +120,8 @@ public class SplitSegmentFragment extends DialogFragment {
}
});
progressBar = view.findViewById(R.id.progress_bar);
listView = (ListView) view.findViewById(R.id.list);
listView.setDivider(null);
listView.setDividerHeight(0);
@ -388,12 +396,16 @@ public class SplitSegmentFragment extends DialogFragment {
return false;
}
public void reloadSplitFragment() {
getFragmentManager()
.beginTransaction()
.detach(this)
.attach(this)
.commit();
@Override
public void dismiss() {
getTrackActivity().updateSplitView();
super.dismiss();
}
@Override
public void onCancel(DialogInterface dialog) {
getTrackActivity().updateSplitView();
super.onCancel(dialog);
}
private class SplitSegmentsAdapter extends ArrayAdapter<GpxDisplayItem> {
@ -652,41 +664,38 @@ public class SplitSegmentFragment extends DialogFragment {
private class SplitTrackAsyncTask extends AsyncTask<Void, Void, Void> {
@Nullable
private final GpxSelectionHelper.SelectedGpxFile mSelectedGpxFile;
@NonNull private final TrackActivity mActivity;
private final List<GpxDisplayGroup> groups;
SplitTrackAsyncTask(@Nullable GpxSelectionHelper.SelectedGpxFile selectedGpxFile, List<GpxDisplayGroup> groups) {
mSelectedGpxFile = selectedGpxFile;
mActivity = getTrackActivity();
this.groups = groups;
}
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
}
protected void onPostExecute(Void result) {
if (!mActivity.isFinishing()) {
mActivity.setSupportProgressBarIndeterminateVisibility(false);
}
progressBar.setVisibility(View.GONE);
if (mSelectedGpxFile != null) {
List<GpxDisplayGroup> groups = getDisplayGroups();
mSelectedGpxFile.setDisplayGroups(groups);
}
updateContent();
}
protected void onPreExecute() {
mActivity.setSupportProgressBarIndeterminateVisibility(true);
if (getTrackActivity() != null) {
updateContent();
}
}
@Override
protected Void doInBackground(Void... params) {
for (GpxDisplayGroup model : groups) {
OsmandApplication application = mActivity.getMyApplication();
if (selectedSplitInterval == 0) {
model.noSplit(application);
model.noSplit(app);
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
model.splitByDistance(application, distanceSplit.get(selectedSplitInterval));
model.splitByDistance(app, distanceSplit.get(selectedSplitInterval));
} else if (timeSplit.get(selectedSplitInterval) > 0) {
model.splitByTime(application, timeSplit.get(selectedSplitInterval));
model.splitByTime(app, timeSplit.get(selectedSplitInterval));
}
}
@ -700,7 +709,7 @@ public class SplitSegmentFragment extends DialogFragment {
public static boolean showInstance(TrackActivity trackActivity) {
try {
SplitSegmentFragment fragment = new SplitSegmentFragment();
SplitSegmentDialogFragment fragment = new SplitSegmentDialogFragment();
fragment.show(trackActivity.getSupportFragmentManager(), TAG);
return true;
} catch (RuntimeException e) {

View file

@ -840,7 +840,6 @@ public class TrackSegmentFragment extends OsmAndListFragment {
for (GpxDisplayItem i : flatten(groups)) {
adapter.add(i);
}
// Obsolete: adapter.setNotifyOnChange(true);
adapter.notifyDataSetChanged();
if (getActivity() != null) {
updateHeader();
@ -1773,7 +1772,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
}
void openSplitIntervalScreen() {
SplitSegmentFragment.showInstance(getTrackActivity());
SplitSegmentDialogFragment.showInstance(getTrackActivity());
}
private class SaveGpxAsyncTask extends AsyncTask<Void, Void, Void> {