Fixed visual representation of settings dialog. Small fixes. First iteration of custom deletion logic.
This commit is contained in:
parent
e009aa5972
commit
574ba29ac1
9 changed files with 205 additions and 53 deletions
|
@ -5,12 +5,17 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/list_header_height"
|
android:layout_height="@dimen/list_header_height"
|
||||||
|
android:paddingLeft="@dimen/dialog_content_margin"
|
||||||
|
android:paddingRight="@dimen/dialog_content_margin"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/text"
|
android:id="@+id/text"
|
||||||
style="@style/DashboardSubHeader"
|
style="@style/DashboardSubHeader"
|
||||||
osmand:typeface="@string/font_roboto_medium"
|
android:layout_marginLeft="0dp"
|
||||||
|
android:textColor="@color/dashboard_black"
|
||||||
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
tools:text="@string/lorem_ipsum"/>
|
tools:text="@string/lorem_ipsum"/>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
|
|
|
@ -2227,4 +2227,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
|
||||||
<string name="try_again">Try again</string>
|
<string name="try_again">Try again</string>
|
||||||
<string name="error_message_pattern">Error: {0}</string>
|
<string name="error_message_pattern">Error: {0}</string>
|
||||||
<string name="dahboard_options_dialog_title">Dashboard options</string>
|
<string name="dahboard_options_dialog_title">Dashboard options</string>
|
||||||
|
<string name="shared_string_card_was_hidden">Card was hidden</string>
|
||||||
|
<string name="shared_string_undo">UNDO</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -15,6 +15,7 @@ import android.widget.FrameLayout;
|
||||||
|
|
||||||
import net.osmand.plus.OsmAndAppCustomization;
|
import net.osmand.plus.OsmAndAppCustomization;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.widgets.InterceptorFrameLayout;
|
import net.osmand.plus.widgets.InterceptorFrameLayout;
|
||||||
import net.osmand.plus.widgets.tools.SwipeDismissTouchListener;
|
import net.osmand.plus.widgets.tools.SwipeDismissTouchListener;
|
||||||
|
@ -73,8 +74,6 @@ public abstract class DashBaseFragment extends Fragment {
|
||||||
public void onDismiss(View view, Object token, boolean isSwipeRight) {
|
public void onDismiss(View view, Object token, boolean isSwipeRight) {
|
||||||
if (isSwipeRight) {
|
if (isSwipeRight) {
|
||||||
getDismissCallback().onDismiss();
|
getDismissCallback().onDismiss();
|
||||||
} else {
|
|
||||||
// TODO show settings card
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -158,7 +157,7 @@ public abstract class DashBaseFragment extends Fragment {
|
||||||
|
|
||||||
private DismissListener defaultDismissListener;
|
private DismissListener defaultDismissListener;
|
||||||
|
|
||||||
private static class DefaultDismissListener implements DismissListener {
|
public static class DefaultDismissListener implements DismissListener {
|
||||||
private View parentView;
|
private View parentView;
|
||||||
private DashboardOnMap dashboardOnMap;
|
private DashboardOnMap dashboardOnMap;
|
||||||
private String fragmentTag;
|
private String fragmentTag;
|
||||||
|
@ -177,15 +176,15 @@ public abstract class DashBaseFragment extends Fragment {
|
||||||
dashboardOnMap.blacklistFragmentByTag(fragmentTag);
|
dashboardOnMap.blacklistFragmentByTag(fragmentTag);
|
||||||
ViewCompat.setTranslationX(fragmentView, 0);
|
ViewCompat.setTranslationX(fragmentView, 0);
|
||||||
ViewCompat.setAlpha(fragmentView, 1);
|
ViewCompat.setAlpha(fragmentView, 1);
|
||||||
Snackbar.make(parentView, "Card was hidden", Snackbar.LENGTH_LONG)
|
Snackbar.make(parentView, dashboardOnMap.getMyApplication().getResources()
|
||||||
.setAction("UNDO", new View.OnClickListener() {
|
.getString(R.string.shared_string_card_was_hidden), Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
DefaultDismissListener.this.onUndo();
|
DefaultDismissListener.this.onUndo();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUndo() {
|
public void onUndo() {
|
||||||
|
|
|
@ -7,6 +7,8 @@ import android.graphics.Typeface;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -14,6 +16,7 @@ import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
|
@ -31,6 +34,8 @@ public class DashErrorFragment extends DashBaseFragment {
|
||||||
|
|
||||||
public static final String TAG = "DASH_ERROR_FRAGMENT";
|
public static final String TAG = "DASH_ERROR_FRAGMENT";
|
||||||
|
|
||||||
|
private DismissListener dismissCallback;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_error_fragment, container, false);
|
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_error_fragment, container, false);
|
||||||
|
@ -47,7 +52,7 @@ public class DashErrorFragment extends DashBaseFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "crash@osmand.net" }); //$NON-NLS-1$
|
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"crash@osmand.net"}); //$NON-NLS-1$
|
||||||
File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH);
|
File file = getMyApplication().getAppPath(OsmandApplication.EXCEPTION_PATH);
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
||||||
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
|
intent.setType("vnd.android.cursor.dir/email"); //$NON-NLS-1$
|
||||||
|
@ -67,6 +72,7 @@ public class DashErrorFragment extends DashBaseFragment {
|
||||||
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
|
text.append("\nApk Version : ").append(info.versionName).append(" ").append(info.versionCode); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
PlatformUtil.getLog(DashErrorFragment.class).error("", e);
|
||||||
}
|
}
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
intent.putExtra(Intent.EXTRA_TEXT, text.toString());
|
||||||
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
startActivity(Intent.createChooser(intent, getString(R.string.send_report)));
|
||||||
|
@ -85,10 +91,53 @@ public class DashErrorFragment extends DashBaseFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dismissCallback = new ErrorDismissListener(getParentView(), dashboard, TAG, view);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpenDash() {
|
public void onOpenDash() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DismissListener getDismissCallback() {
|
||||||
|
return dismissCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ErrorDismissListener implements DismissListener {
|
||||||
|
private View parentView;
|
||||||
|
private DashboardOnMap dashboardOnMap;
|
||||||
|
private String fragmentTag;
|
||||||
|
private View fragmentView;
|
||||||
|
|
||||||
|
public ErrorDismissListener(View parentView, DashboardOnMap dashboardOnMap,
|
||||||
|
String fragmentTag, View fragmentView) {
|
||||||
|
this.parentView = parentView;
|
||||||
|
this.dashboardOnMap = dashboardOnMap;
|
||||||
|
this.fragmentTag = fragmentTag;
|
||||||
|
this.fragmentView = fragmentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss() {
|
||||||
|
dashboardOnMap.hideFragmentByTag(fragmentTag);
|
||||||
|
ViewCompat.setTranslationX(fragmentView, 0);
|
||||||
|
ViewCompat.setAlpha(fragmentView, 1);
|
||||||
|
Snackbar.make(parentView, dashboardOnMap.getMyApplication().getResources()
|
||||||
|
.getString(R.string.shared_string_card_was_hidden), Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
ErrorDismissListener.this.onUndo();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUndo() {
|
||||||
|
dashboardOnMap.unhideFragmentByTag(fragmentTag);
|
||||||
|
ViewCompat.setTranslationX(fragmentView, 0);
|
||||||
|
ViewCompat.setAlpha(fragmentView, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v4.view.ViewCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -24,14 +26,13 @@ import java.util.Calendar;
|
||||||
*/
|
*/
|
||||||
public class DashRateUsFragment extends DashBaseFragment {
|
public class DashRateUsFragment extends DashBaseFragment {
|
||||||
public static final String TAG = "DASH_RATE_US_FRAGMENT";
|
public static final String TAG = "DASH_RATE_US_FRAGMENT";
|
||||||
|
|
||||||
// TODO move to resources
|
// TODO move to resources
|
||||||
public static final String EMAIL = "support@osmand.net";
|
public static final String EMAIL = "support@osmand.net";
|
||||||
|
|
||||||
// Imported in shouldShow method
|
// Imported in shouldShow method
|
||||||
private static OsmandSettings settings;
|
private static OsmandSettings settings;
|
||||||
private FragmentState state = FragmentState.INITIAL_STATE;
|
private FragmentState state = FragmentState.INITIAL_STATE;
|
||||||
|
private RateUsDismissListener mRateUsDismissListener;
|
||||||
@Override
|
@Override
|
||||||
public void onOpenDash() {
|
public void onOpenDash() {
|
||||||
|
|
||||||
|
@ -48,6 +49,7 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
new PositiveButtonListener(header, subheader, positiveButton, negativeButton));
|
new PositiveButtonListener(header, subheader, positiveButton, negativeButton));
|
||||||
negativeButton.setOnClickListener(
|
negativeButton.setOnClickListener(
|
||||||
new NegativeButtonListener(header, subheader, positiveButton, negativeButton));
|
new NegativeButtonListener(header, subheader, positiveButton, negativeButton));
|
||||||
|
mRateUsDismissListener = new RateUsDismissListener(getParentView(), dashboard, TAG, view, settings);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,13 +104,15 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
// Initial state now
|
// Initial state now
|
||||||
modifiedTime.add(Calendar.HOUR, -72);
|
modifiedTime.add(Calendar.HOUR, -72);
|
||||||
bannerFreeRuns = 3;
|
bannerFreeRuns = 3;
|
||||||
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
|
return modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns;
|
||||||
toReturn = true;
|
|
||||||
}
|
|
||||||
return toReturn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PositiveButtonListener implements View.OnClickListener {
|
@Override
|
||||||
|
public DismissListener getDismissCallback() {
|
||||||
|
return mRateUsDismissListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PositiveButtonListener implements View.OnClickListener {
|
||||||
private TextView header;
|
private TextView header;
|
||||||
private TextView subheader;
|
private TextView subheader;
|
||||||
private Button positiveButton;
|
private Button positiveButton;
|
||||||
|
@ -222,4 +226,52 @@ public class DashRateUsFragment extends DashBaseFragment {
|
||||||
&& super.shouldShow(settings, activity, tag);
|
&& super.shouldShow(settings, activity, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class RateUsDismissListener implements DismissListener {
|
||||||
|
private View parentView;
|
||||||
|
private DashboardOnMap dashboardOnMap;
|
||||||
|
private String fragmentTag;
|
||||||
|
private View fragmentView;
|
||||||
|
private OsmandSettings settings;
|
||||||
|
private int exNumberOfRuns;
|
||||||
|
private long exLastDisplayTime;
|
||||||
|
public RateUsDismissListener(View parentView, DashboardOnMap dashboardOnMap,
|
||||||
|
String fragmentTag, View fragmentView, OsmandSettings settings) {
|
||||||
|
this.parentView = parentView;
|
||||||
|
this.dashboardOnMap = dashboardOnMap;
|
||||||
|
this.fragmentTag = fragmentTag;
|
||||||
|
this.fragmentView = fragmentView;
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss() {
|
||||||
|
dashboardOnMap.hideFragmentByTag(fragmentTag);
|
||||||
|
ViewCompat.setTranslationX(fragmentView, 0);
|
||||||
|
ViewCompat.setAlpha(fragmentView, 1);
|
||||||
|
Snackbar.make(parentView, dashboardOnMap.getMyApplication().getResources()
|
||||||
|
.getString(R.string.shared_string_card_was_hidden), Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
RateUsDismissListener.this.onUndo(exNumberOfRuns, exLastDisplayTime);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
settings.RATE_US_STATE.set(RateUsState.IGNORED);
|
||||||
|
exNumberOfRuns = settings.NUMBER_OF_APPLICATION_STARTS.get();
|
||||||
|
settings.NUMBER_OF_APPLICATION_STARTS.set(0);
|
||||||
|
exLastDisplayTime = settings.LAST_DISPLAY_TIME.get();
|
||||||
|
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onUndo(int numberOfRuns, long lastDisplayTime) {
|
||||||
|
dashboardOnMap.unhideFragmentByTag(fragmentTag);
|
||||||
|
ViewCompat.setTranslationX(fragmentView, 0);
|
||||||
|
ViewCompat.setAlpha(fragmentView, 1);
|
||||||
|
settings.NUMBER_OF_APPLICATION_STARTS.set(numberOfRuns);
|
||||||
|
settings.LAST_DISPLAY_TIME.set(lastDisplayTime);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,15 +82,15 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
private static final DashFragmentData.ShouldShowFunction rateUsShouldShow = new DashRateUsFragment.RateUsShouldShow();
|
private static final DashFragmentData.ShouldShowFunction rateUsShouldShow = new DashRateUsFragment.RateUsShouldShow();
|
||||||
private static final DefaultShouldShow defaultShouldShow = new DefaultShouldShow();
|
private static final DefaultShouldShow defaultShouldShow = new DefaultShouldShow();
|
||||||
private static final DefaultShouldShow errorShouldShow = new ErrorShouldShow();
|
private static final DefaultShouldShow errorShouldShow = new ErrorShouldShow();
|
||||||
private static final DefaultShouldShow firstTimeShouldShow = new FirstTimeShouldShow();
|
private static final DashFragmentData.ShouldShowFunction firstTimeShouldShow = new FirstTimeShouldShow();
|
||||||
private static final DefaultShouldShow simulateShouldShow = new SimulateShouldShow();
|
private static final DefaultShouldShow simulateShouldShow = new SimulateShouldShow();
|
||||||
private static final DashFragmentData.ShouldShowFunction chooseAppDirShouldShow = new ChooseAppDirShouldShow();
|
private static final DashFragmentData.ShouldShowFunction chooseAppDirShouldShow = new ChooseAppDirShouldShow();
|
||||||
|
|
||||||
private static final DashFragmentData[] fragmentsData = new DashFragmentData[]{
|
private static final DashFragmentData[] fragmentsData = new DashFragmentData[]{
|
||||||
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us", rateUsShouldShow),
|
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us", rateUsShouldShow, true),
|
||||||
new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time", firstTimeShouldShow),
|
new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time", firstTimeShouldShow, true),
|
||||||
new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir", chooseAppDirShouldShow),
|
new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir", chooseAppDirShouldShow, true),
|
||||||
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error", errorShouldShow),
|
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error", errorShouldShow, true),
|
||||||
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class, "Navigation", defaultShouldShow),
|
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class, "Navigation", defaultShouldShow),
|
||||||
new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking", defaultShouldShow),
|
new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking", defaultShouldShow),
|
||||||
new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class, "Waypoints", defaultShouldShow),
|
new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class, "Waypoints", defaultShouldShow),
|
||||||
|
@ -117,7 +117,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
private DashboardType visibleType;
|
private DashboardType visibleType;
|
||||||
private DashboardType previousVisibleType;
|
private DashboardType previousVisibleType;
|
||||||
private boolean landscape;
|
private boolean landscape;
|
||||||
private List<WeakReference<DashBaseFragment>> fragList = new LinkedList<WeakReference<DashBaseFragment>>();
|
private List<WeakReference<DashBaseFragment>> fragList = new LinkedList<>();
|
||||||
private net.osmand.Location myLocation;
|
private net.osmand.Location myLocation;
|
||||||
private LatLon mapViewLocation;
|
private LatLon mapViewLocation;
|
||||||
private float heading;
|
private float heading;
|
||||||
|
@ -246,7 +246,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
lst.setVisibility(View.GONE);
|
lst.setVisibility(View.GONE);
|
||||||
ImageView back = (ImageView) dashboardView.findViewById(R.id.toolbar_back);
|
ImageView back = (ImageView) dashboardView.findViewById(R.id.toolbar_back);
|
||||||
back.setImageDrawable(
|
back.setImageDrawable(
|
||||||
((OsmandApplication) getMyApplication()).getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
|
||||||
back.setOnClickListener(new View.OnClickListener() {
|
back.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -466,7 +466,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
scrollView.setVisibility(View.GONE);
|
scrollView.setVisibility(View.GONE);
|
||||||
listViewLayout.setVisibility(View.VISIBLE);
|
listViewLayout.setVisibility(View.VISIBLE);
|
||||||
if (listView instanceof ObservableListView) {
|
if (listView instanceof ObservableListView) {
|
||||||
onScrollChanged(((ObservableListView) listView).getScrollY(), false, false);
|
onScrollChanged(listView.getScrollY(), false, false);
|
||||||
}
|
}
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
refreshContent(false);
|
refreshContent(false);
|
||||||
|
@ -600,7 +600,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
hideDashboard(false);
|
hideDashboard(false);
|
||||||
final Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
|
final Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
|
||||||
.getDownloadIndexActivity());
|
.getDownloadIndexActivity());
|
||||||
intent.putExtra(DownloadActivity.FILTER_KEY, f.toString());
|
intent.putExtra(DownloadActivity.FILTER_KEY, f);
|
||||||
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
|
intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB);
|
||||||
mapActivity.startActivity(intent);
|
mapActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
@ -824,9 +824,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
gradientToolbar.setAlpha((int) ((1 - t) * 255));
|
gradientToolbar.setAlpha((int) ((1 - t) * 255));
|
||||||
setAlpha(dashboardView, (int) (t * 128), 0);
|
setAlpha(dashboardView, (int) (t * 128), 0);
|
||||||
if (t < 1) {
|
if (t < 1) {
|
||||||
((Toolbar) dashboardView.findViewById(R.id.toolbar)).setBackgroundDrawable(gradientToolbar);
|
dashboardView.findViewById(R.id.toolbar).setBackgroundDrawable(gradientToolbar);
|
||||||
} else {
|
} else {
|
||||||
((Toolbar) dashboardView.findViewById(R.id.toolbar)).setBackgroundColor(0xff000000 | baseColor);
|
dashboardView.findViewById(R.id.toolbar).setBackgroundColor(0xff000000 | baseColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -905,23 +905,29 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void blacklistFragmentByTag(String tag) {
|
public void blacklistFragmentByTag(String tag) {
|
||||||
FragmentManager manager = mapActivity.getSupportFragmentManager();
|
hideFragmentByTag(tag);
|
||||||
FragmentTransaction transaction = manager.beginTransaction();
|
|
||||||
Fragment frag = manager.findFragmentByTag(tag);
|
|
||||||
transaction.hide(frag).commit();
|
|
||||||
|
|
||||||
getMyApplication().getSettings().registerBooleanPreference(SHOULD_SHOW + tag, true)
|
getMyApplication().getSettings().registerBooleanPreference(SHOULD_SHOW + tag, true)
|
||||||
.makeGlobal().set(false);
|
.makeGlobal().set(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void hideFragmentByTag(String tag) {
|
||||||
|
FragmentManager manager = mapActivity.getSupportFragmentManager();
|
||||||
|
FragmentTransaction transaction = manager.beginTransaction();
|
||||||
|
Fragment frag = manager.findFragmentByTag(tag);
|
||||||
|
transaction.hide(frag).commit();
|
||||||
|
}
|
||||||
|
|
||||||
public void unblacklistFragmentClass(String tag) {
|
public void unblacklistFragmentClass(String tag) {
|
||||||
|
unhideFragmentByTag(tag);
|
||||||
|
getMyApplication().getSettings().registerBooleanPreference(SHOULD_SHOW + tag, true)
|
||||||
|
.makeGlobal().set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unhideFragmentByTag(String tag) {
|
||||||
FragmentManager manager = mapActivity.getSupportFragmentManager();
|
FragmentManager manager = mapActivity.getSupportFragmentManager();
|
||||||
FragmentTransaction transaction = manager.beginTransaction();
|
FragmentTransaction transaction = manager.beginTransaction();
|
||||||
Fragment frag = manager.findFragmentByTag(tag);
|
Fragment frag = manager.findFragmentByTag(tag);
|
||||||
transaction.show(frag).commit();
|
transaction.show(frag).commit();
|
||||||
|
|
||||||
getMyApplication().getSettings().registerBooleanPreference(SHOULD_SHOW + tag, true)
|
|
||||||
.makeGlobal().set(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
View getParentView() {
|
View getParentView() {
|
||||||
|
@ -935,11 +941,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
public static class SettingsShouldShow implements DashFragmentData.ShouldShowFunction {
|
public static class SettingsShouldShow implements DashFragmentData.ShouldShowFunction {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||||
Log.v(TAG, "shouldShow(" + "settings=" + settings + ", activity=" + activity + ", tag=" + tag + ")");
|
return settings.registerBooleanPreference(SHOULD_SHOW + tag, true)
|
||||||
boolean shouldShow = settings.registerBooleanPreference(SHOULD_SHOW + tag, true)
|
|
||||||
.makeGlobal().get();
|
.makeGlobal().get();
|
||||||
Log.v(TAG, "shouldShow=" + shouldShow);
|
|
||||||
return shouldShow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static class DefaultShouldShow extends SettingsShouldShow {
|
public static class DefaultShouldShow extends SettingsShouldShow {
|
||||||
|
@ -958,10 +961,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FirstTimeShouldShow extends DefaultShouldShow {
|
private static class FirstTimeShouldShow extends SettingsShouldShow {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
public boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag) {
|
||||||
return !super.shouldShow(settings, activity, tag);
|
return activity.getMyApplication().getAppInitializer().isFirstTime(activity)
|
||||||
|
&& super.shouldShow(settings, activity, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,17 @@ public final class DashFragmentData {
|
||||||
public final Class<? extends DashBaseFragment> fragmentClass;
|
public final Class<? extends DashBaseFragment> fragmentClass;
|
||||||
public final String title;
|
public final String title;
|
||||||
public final ShouldShowFunction shouldShowFunction;
|
public final ShouldShowFunction shouldShowFunction;
|
||||||
|
public final boolean customDeletionLogic;
|
||||||
|
|
||||||
|
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
|
||||||
|
String title, ShouldShowFunction shouldShowFunction,
|
||||||
|
boolean customDeletionLogic) {
|
||||||
|
this.tag = tag;
|
||||||
|
this.fragmentClass = fragmentClass;
|
||||||
|
this.title = title;
|
||||||
|
this.shouldShowFunction = shouldShowFunction;
|
||||||
|
this.customDeletionLogic = customDeletionLogic;
|
||||||
|
}
|
||||||
|
|
||||||
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
|
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
|
||||||
String title, ShouldShowFunction shouldShowFunction) {
|
String title, ShouldShowFunction shouldShowFunction) {
|
||||||
|
@ -16,6 +27,7 @@ public final class DashFragmentData {
|
||||||
this.fragmentClass = fragmentClass;
|
this.fragmentClass = fragmentClass;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.shouldShowFunction = shouldShowFunction;
|
this.shouldShowFunction = shouldShowFunction;
|
||||||
|
customDeletionLogic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ShouldShowFunction {
|
public interface ShouldShowFunction {
|
||||||
|
|
|
@ -20,15 +20,23 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.dashboard.DashboardOnMap;
|
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class DashboardSettingsDialogFragment extends DialogFragment {
|
public class DashboardSettingsDialogFragment extends DialogFragment {
|
||||||
|
private static final String CHECKED_ITEMS = "checked_items";
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
private DashFragmentData[] fragmentsData;
|
private DashFragmentData[] fragmentsData;
|
||||||
|
private DashFragmentAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
mapActivity = (MapActivity) activity;
|
mapActivity = (MapActivity) activity;
|
||||||
fragmentsData = mapActivity.getDashboard().getFragmentsData();
|
ArrayList<DashFragmentData> fragmentsList = new ArrayList<>();
|
||||||
|
for(DashFragmentData fragmentData : mapActivity.getDashboard().getFragmentsData()) {
|
||||||
|
if (!fragmentData.customDeletionLogic) fragmentsList.add(fragmentData);
|
||||||
|
}
|
||||||
|
fragmentsData = fragmentsList.toArray(new DashFragmentData[fragmentsList.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -36,9 +44,13 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
|
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
|
||||||
final DashFragmentAdapter adapter =
|
if (savedInstanceState != null && savedInstanceState.containsKey(CHECKED_ITEMS)) {
|
||||||
new DashFragmentAdapter(getActivity(), fragmentsData,
|
adapter = new DashFragmentAdapter(getActivity(), fragmentsData,
|
||||||
settings);
|
savedInstanceState.getBooleanArray(CHECKED_ITEMS));
|
||||||
|
} else {
|
||||||
|
adapter = new DashFragmentAdapter(getActivity(), fragmentsData,
|
||||||
|
settings);
|
||||||
|
}
|
||||||
builder.setTitle(R.string.dahboard_options_dialog_title)
|
builder.setTitle(R.string.dahboard_options_dialog_title)
|
||||||
.setAdapter(adapter, null)
|
.setAdapter(adapter, null)
|
||||||
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||||
|
@ -52,14 +64,25 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
mapActivity.getDashboard().refreshDashboardFragments();
|
mapActivity.getDashboard().refreshDashboardFragments();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
final AlertDialog dialog = builder.create();
|
.setNegativeButton(R.string.shared_string_cancel, null);
|
||||||
return dialog;
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putBooleanArray(CHECKED_ITEMS, adapter.getCheckedItems());
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DashFragmentAdapter extends ArrayAdapter<DashFragmentData> {
|
private static class DashFragmentAdapter extends ArrayAdapter<DashFragmentData> {
|
||||||
private final boolean[] checkedItems;
|
private final boolean[] checkedItems;
|
||||||
|
|
||||||
|
public DashFragmentAdapter(Context context, DashFragmentData[] objects, boolean[] checkedItems) {
|
||||||
|
super(context, 0, objects);
|
||||||
|
this.checkedItems = checkedItems;
|
||||||
|
}
|
||||||
|
|
||||||
public DashFragmentAdapter(Context context, DashFragmentData[] objects, OsmandSettings settings) {
|
public DashFragmentAdapter(Context context, DashFragmentData[] objects, OsmandSettings settings) {
|
||||||
super(context, 0, objects);
|
super(context, 0, objects);
|
||||||
checkedItems = new boolean[objects.length];
|
checkedItems = new boolean[objects.length];
|
||||||
|
@ -83,16 +106,21 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
|
||||||
new CompoundButton.OnCheckedChangeListener() {
|
new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||||
Integer position = (Integer) compoundButton.getTag();
|
DashViewHolder localViewHolder = (DashViewHolder) compoundButton.getTag();
|
||||||
checkedItems[position] = b;
|
checkedItems[localViewHolder.position] = b;
|
||||||
|
localViewHolder.textView.setTextColor(
|
||||||
|
checkedItems[localViewHolder.position] ? 0xFF212121
|
||||||
|
: 0xFF8c8c8c);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
viewHolder = (DashViewHolder) convertView.getTag();
|
viewHolder = (DashViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
viewHolder.compoundButton.setTag(position);
|
viewHolder.position = position;
|
||||||
|
viewHolder.compoundButton.setTag(viewHolder);
|
||||||
viewHolder.compoundButton.setChecked(checkedItems[position]);
|
viewHolder.compoundButton.setChecked(checkedItems[position]);
|
||||||
viewHolder.textView.setText(dashFragmentData.title);
|
viewHolder.textView.setText(dashFragmentData.title);
|
||||||
|
viewHolder.textView.setTextColor(checkedItems[position] ? 0xFF212121 : 0xFF8c8c8c);
|
||||||
convertView.setTag(viewHolder);
|
convertView.setTag(viewHolder);
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
@ -104,6 +132,7 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
|
||||||
private class DashViewHolder {
|
private class DashViewHolder {
|
||||||
TextView textView;
|
TextView textView;
|
||||||
CompoundButton compoundButton;
|
CompoundButton compoundButton;
|
||||||
|
int position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue