Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Feb 28, 2024
1 parent b2fcf5c commit a0d598f
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 19 deletions.
92 changes: 73 additions & 19 deletions src/main/java/de/blau/android/dialogs/Newbie.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
}
100 changes: 100 additions & 0 deletions src/main/res/layout/welcome_tabs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<de.blau.android.views.ExtendedViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/welcome_page"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="?attr/dialogPreferredPadding"
android:paddingRight="?attr/dialogPreferredPadding"
android:orientation="vertical">
<TextView
android:id="@+id/welcome_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="@+id/settings_page"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="?attr/dialogPreferredPadding"
android:paddingRight="?attr/dialogPreferredPadding">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<RelativeLayout
android:id="@+id/upload_comment_controls"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top">

<TextView
android:id="@+id/upload_close_open_changeset_label"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_below="@id/upload_source"
android:gravity="center_vertical"
android:text="@string/upload_close_open_changeset_label" />
<CheckBox
android:id="@+id/upload_close_open_changeset"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignBottom="@id/upload_close_open_changeset_label"
android:layout_alignEnd="@id/upload_source"
android:layout_alignRight="@id/upload_source"
android:layout_alignTop="@id/upload_close_open_changeset_label"
android:layout_below="@id/upload_source"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="@+id/upload_close_changeset_label"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_below="@id/upload_close_open_changeset_label"
android:gravity="center_vertical"
android:text="@string/upload_close_changeset_label" />
<CheckBox
android:id="@+id/upload_close_changeset"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignBottom="@id/upload_close_changeset_label"
android:layout_alignEnd="@id/upload_close_open_changeset"
android:layout_alignRight="@id/upload_close_open_changeset"
android:layout_alignTop="@id/upload_close_changeset_label"
android:layout_below="@id/upload_source"
android:gravity="center_vertical"
android:text="" />
<TextView
android:id="@+id/upload_request_review_label"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_below="@id/upload_close_changeset_label"
android:gravity="center_vertical"
android:text="@string/upload_request_review_label" />
<CheckBox
android:id="@+id/upload_request_review"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_alignBottom="@id/upload_request_review_label"
android:layout_alignEnd="@id/upload_close_changeset"
android:layout_alignRight="@id/upload_close_changeset"
android:layout_below="@id/upload_close_changeset"
android:gravity="center_vertical"
android:text="" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
</de.blau.android.views.ExtendedViewPager>
</LinearLayout>

0 comments on commit a0d598f

Please sign in to comment.