diff --git a/src/main/java/de/blau/android/dialogs/Newbie.java b/src/main/java/de/blau/android/dialogs/Newbie.java index 825cb46385..09a187ced0 100644 --- a/src/main/java/de/blau/android/dialogs/Newbie.java +++ b/src/main/java/de/blau/android/dialogs/Newbie.java @@ -1,19 +1,31 @@ package de.blau.android.dialogs; import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnShowListener; import android.os.Bundle; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog.Builder; import androidx.appcompat.app.AppCompatDialog; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; +import androidx.viewpager.widget.PagerTabStrip; import de.blau.android.HelpViewer; import de.blau.android.Main; import de.blau.android.R; import de.blau.android.util.ImmersiveDialogFragment; +import de.blau.android.util.OnPageSelectedListener; +import de.blau.android.util.ThemeUtils; import de.blau.android.util.Util; +import de.blau.android.views.ExtendedViewPager; /** * Display a dialog giving new users minimal instructions @@ -77,31 +89,73 @@ public void onAttach(Context context) { @NonNull @Override public AppCompatDialog onCreateDialog(Bundle savedInstanceState) { - Builder builder = new AlertDialog.Builder(getActivity()); + final FragmentActivity activity = getActivity(); + Builder builder = new AlertDialog.Builder(activity); builder.setIcon(null); builder.setTitle(R.string.welcome_title); + final LayoutInflater inflater = ThemeUtils.getLayoutInflater(activity); + final View layout = inflater.inflate(R.layout.welcome_tabs, null); + final ExtendedViewPager pager = (ExtendedViewPager) layout.findViewById(R.id.pager); + pager.setAdapter(new ViewPagerAdapter(activity, layout, new int[] { R.id.welcome_page, R.id.settings_page }, + new int[] { R.string.confirm_upload_edits_page, R.string.menu_tags })); + pager.addOnPageChangeListener((OnPageSelectedListener) position -> { + AlertDialog dialog = ((AlertDialog) getDialog()); + if (dialog != null) { + Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE); + Button negative = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); + positive.clearFocus(); + if (position == 0) { + positive.setText(R.string.next); + positive.setOnClickListener((View v) -> { + pager.setCurrentItem(2); + }); + negative.setText(R.string.skip); + negative.setOnClickListener((View v) -> getDialog().dismiss()); + } + if (position == 1) { + positive.setText("Start mapping!"); + positive.setOnClickListener((View v) -> { + Context ctx = v.getContext(); + if (ctx instanceof Main) { + getDialog().dismiss(); + ((Main) ctx).gotoCurrentLocation(); + ((Main) ctx).setFollowGPS(true); + } + }); + negative.setText(R.string.back); + negative.setOnClickListener((View v) -> { + pager.setCurrentItem(0); + }); + } + } + }); + String message = getString(R.string.welcome_message); if (main.isFullScreen()) { message = message + getString(R.string.welcome_message_fullscreen); } - builder.setMessage(Util.fromHtml(message)); - builder.setPositiveButton(R.string.okay, (dialog, which) -> { - FragmentActivity activity = getActivity(); - if (activity instanceof Main) { - main.gotoCurrentLocation(); - main.setFollowGPS(true); - } else { - Log.e(DEBUG_TAG, "getActivity returned null in onClick"); - } - }); - builder.setNeutralButton(R.string.read_introduction, (dialog, which) -> { - FragmentActivity activity = getActivity(); - if (activity != null) { - HelpViewer.start(activity, R.string.help_introduction); - } else { - Log.e(DEBUG_TAG, "getActivity returned null in onClick"); - } + ((TextView) layout.findViewById(R.id.welcome_message)).setText(Util.fromHtml(message)); + builder.setView(layout); + + builder.setNegativeButton(R.string.skip, null); + builder.setPositiveButton(R.string.next, null); + builder.setNeutralButton(R.string.read_introduction, null); + AlertDialog dialog = builder.create(); + dialog.setOnShowListener((DialogInterface d) -> { + Button neutral = dialog.getButton(DialogInterface.BUTTON_NEUTRAL); + neutral.setOnClickListener((View v) -> { + Context ctx = v.getContext(); + if (ctx instanceof FragmentActivity) { + HelpViewer.start((FragmentActivity) ctx, R.string.help_introduction); + } else { + System.out.println("Not a fragment activity"); + } + }); + Button positive = dialog.getButton(DialogInterface.BUTTON_POSITIVE); + positive.setOnClickListener((View v) -> { + pager.setCurrentItem(1); + }); }); - return builder.create(); + return dialog; } } diff --git a/src/main/res/layout/welcome_tabs.xml b/src/main/res/layout/welcome_tabs.xml new file mode 100644 index 0000000000..116cfd42c9 --- /dev/null +++ b/src/main/res/layout/welcome_tabs.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file