Merge branch 'my_places_favourites' into sasha_pasha_branch
This commit is contained in:
commit
1f4edccf1f
15 changed files with 418 additions and 56 deletions
58
OsmAnd/res/layout-land/empty_state_favourites.xml
Normal file
58
OsmAnd/res/layout-land/empty_state_favourites.xml
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_image_margin_top"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_image_margin_bottom"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginLeft="@dimen/my_places_empty_state_image_margin_left"
|
||||
android:layout_marginStart="@dimen/my_places_empty_state_image_margin_left"
|
||||
android:id="@+id/empty_state_image_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
tools:src="@drawable/ic_empty_state_favorites_night_result"/>
|
||||
|
||||
<LinearLayout
|
||||
android:clipToPadding="false"
|
||||
android:paddingLeft="@dimen/my_places_empty_state_text_button_padding_left"
|
||||
android:paddingStart="@dimen/my_places_empty_state_text_button_padding_left"
|
||||
android:paddingRight="@dimen/my_places_empty_state_text_button_padding_right"
|
||||
android:paddingEnd="@dimen/my_places_empty_state_text_button_padding_right"
|
||||
android:paddingTop="@dimen/my_places_empty_state_text_button_padding_top"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_text_interval"
|
||||
android:background="@null"
|
||||
android:text="@string/empty_state_favourites"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:text="@string/empty_state_favourites_desc"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_desc_size"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/import_button"
|
||||
style="@style/DialogActionButton"
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_button_margin_top"
|
||||
android:text="@string/shared_string_import"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
58
OsmAnd/res/layout-land/empty_state_my_tracks.xml
Normal file
58
OsmAnd/res/layout-land/empty_state_my_tracks.xml
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_image_margin_top"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_image_margin_bottom"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_marginLeft="@dimen/my_places_empty_state_image_margin_left"
|
||||
android:layout_marginStart="@dimen/my_places_empty_state_image_margin_left"
|
||||
android:id="@+id/empty_state_image_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
tools:src="@drawable/ic_empty_state_trip_night_result"/>
|
||||
|
||||
<LinearLayout
|
||||
android:clipToPadding="false"
|
||||
android:paddingLeft="@dimen/my_places_empty_state_text_button_padding_left"
|
||||
android:paddingStart="@dimen/my_places_empty_state_text_button_padding_left"
|
||||
android:paddingRight="@dimen/my_places_empty_state_text_button_padding_right"
|
||||
android:paddingEnd="@dimen/my_places_empty_state_text_button_padding_right"
|
||||
android:paddingTop="@dimen/my_places_empty_state_text_button_padding_top"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_text_interval"
|
||||
android:background="@null"
|
||||
android:text="@string/empty_state_my_tracks"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:text="@string/empty_state_my_tracks_desc"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_desc_size"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/import_button"
|
||||
style="@style/DialogActionButton"
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_button_margin_top"
|
||||
android:text="@string/shared_string_import"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,8 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/ctx_menu_info_view_bg"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ExpandableListView
|
||||
android:id="@android:id/list"
|
||||
|
@ -17,4 +18,6 @@
|
|||
android:drawSelectorOnTop="false"
|
||||
android:groupIndicator="@android:color/transparent"/>
|
||||
|
||||
<include layout="@layout/empty_state_my_tracks"/>
|
||||
|
||||
</LinearLayout>
|
46
OsmAnd/res/layout/empty_state_favourites.xml
Normal file
46
OsmAnd/res/layout/empty_state_favourites.xml
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/empty_state_image_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_image_margin_bottom"
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_image_margin_top"
|
||||
tools:src="@drawable/ic_empty_state_favorites_night_result"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_text_interval"
|
||||
android:background="@null"
|
||||
android:text="@string/empty_state_favourites"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_size"/>
|
||||
|
||||
<TextView
|
||||
android:gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:layout_marginLeft="@dimen/my_places_empty_state_text_desc_margin"
|
||||
android:layout_marginRight="@dimen/my_places_empty_state_text_desc_margin"
|
||||
android:text="@string/empty_state_favourites_desc"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_desc_size"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/import_button"
|
||||
style="@style/DialogActionButton"
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_button_margin_top"
|
||||
android:text="@string/shared_string_import"/>
|
||||
|
||||
</LinearLayout>
|
46
OsmAnd/res/layout/empty_state_my_tracks.xml
Normal file
46
OsmAnd/res/layout/empty_state_my_tracks.xml
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@android:id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/empty_state_image_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_image_margin_bottom"
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_image_margin_top"
|
||||
tools:src="@drawable/ic_empty_state_trip_night_result"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/my_places_empty_state_text_interval"
|
||||
android:background="@null"
|
||||
android:text="@string/empty_state_my_tracks"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<TextView
|
||||
android:gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:layout_marginLeft="@dimen/my_places_empty_state_text_desc_margin"
|
||||
android:layout_marginRight="@dimen/my_places_empty_state_text_desc_margin"
|
||||
android:text="@string/empty_state_my_tracks_desc"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/my_places_empty_state_text_desc_size"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/import_button"
|
||||
style="@style/DialogActionButton"
|
||||
android:layout_marginTop="@dimen/my_places_empty_state_button_margin_top"
|
||||
android:text="@string/shared_string_import"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,9 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/MainLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
android:id="@+id/MainLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="?attr/ctx_menu_info_view_bg">
|
||||
|
||||
<ExpandableListView
|
||||
android:id="@android:id/list"
|
||||
|
@ -16,6 +17,8 @@
|
|||
android:divider="@null"
|
||||
android:dividerHeight="0dp"
|
||||
android:drawSelectorOnTop="false"
|
||||
android:groupIndicator="@android:color/transparent" />
|
||||
android:groupIndicator="@android:color/transparent"/>
|
||||
|
||||
<include layout="@layout/empty_state_favourites"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -4,4 +4,7 @@
|
|||
|
||||
<dimen name="splash_screen_logo_top">24dp</dimen>
|
||||
<dimen name="splash_screen_text_bottom">48dp</dimen>
|
||||
|
||||
<dimen name="my_places_empty_state_image_margin_top">39dp</dimen>
|
||||
<dimen name="my_places_empty_state_image_margin_bottom">39dp</dimen>
|
||||
</resources>
|
5
OsmAnd/res/values-large-land/sizes.xml
Normal file
5
OsmAnd/res/values-large-land/sizes.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="my_places_empty_state_image_margin_top">59dp</dimen>
|
||||
<dimen name="my_places_empty_state_image_margin_bottom">59dp</dimen>
|
||||
</resources>
|
|
@ -79,4 +79,16 @@
|
|||
<dimen name="default_split_segments_data">15sp</dimen>
|
||||
<dimen name="default_split_segments_sub">12sp</dimen>
|
||||
|
||||
<dimen name="my_places_empty_state_image_margin_top">63dp</dimen>
|
||||
<dimen name="my_places_empty_state_image_margin_bottom">45dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_interval">12dp</dimen>
|
||||
<dimen name="my_places_empty_state_button_margin_top">30dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_size">20sp</dimen>
|
||||
<dimen name="my_places_empty_state_text_desc_size">18sp</dimen>
|
||||
<dimen name="my_places_empty_state_text_desc_margin">68dp</dimen>
|
||||
<dimen name="my_places_empty_state_image_margin_left">138dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_button_padding_left">72dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_button_padding_right">90dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_button_padding_top">96dp</dimen>
|
||||
|
||||
</resources>
|
|
@ -143,4 +143,16 @@
|
|||
|
||||
<dimen name="splash_screen_logo_top">150dp</dimen>
|
||||
<dimen name="splash_screen_text_bottom">128dp</dimen>
|
||||
|
||||
<dimen name="my_places_empty_state_image_margin_top">42dp</dimen>
|
||||
<dimen name="my_places_empty_state_image_margin_bottom">30dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_interval">8dp</dimen>
|
||||
<dimen name="my_places_empty_state_button_margin_top">20dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_size">18sp</dimen>
|
||||
<dimen name="my_places_empty_state_text_desc_size">16sp</dimen>
|
||||
<dimen name="my_places_empty_state_text_desc_margin">45dp</dimen>
|
||||
<dimen name="my_places_empty_state_image_margin_left">92dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_button_padding_left">48dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_button_padding_right">60dp</dimen>
|
||||
<dimen name="my_places_empty_state_text_button_padding_top">64dp</dimen>
|
||||
</resources>
|
|
@ -2669,4 +2669,10 @@
|
|||
<string name="save_route_point">Save Route Point</string>
|
||||
<string name="waypoint_one">Waypoint 1</string>
|
||||
<string name="route_point_one">Route Point 1</string>
|
||||
<string name="empty_state_my_tracks">Add and Record Tracks</string>
|
||||
<string name="empty_state_my_tracks_desc">Record or import tracks to view</string>
|
||||
<string name="empty_state_favourites">Add Favorites</string>
|
||||
<string name="empty_state_favourites_desc">Add favorites on map or import them from filesystem</string>
|
||||
<string name="import_track">Import track</string>
|
||||
<string name="import_track_desc">File %1$s does not contain waypoints, import it as a track?</string>
|
||||
</resources>
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.Filter;
|
||||
|
@ -71,11 +72,13 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
public static final int SHARE_ID = 4;
|
||||
public static final int SELECT_MAP_MARKERS_ID = 5;
|
||||
public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6;
|
||||
public static final int IMPORT_FAVOURITES_ID = 7;
|
||||
public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded";
|
||||
|
||||
private FavouritesAdapter favouritesAdapter = new FavouritesAdapter();
|
||||
private FavouritesDbHelper helper;
|
||||
|
||||
private OsmandApplication app;
|
||||
private boolean selectionMode = false;
|
||||
private Set<FavouritePoint> favoritesSelected = new LinkedHashSet<>();
|
||||
private Set<FavoriteGroup> groupsToDelete = new LinkedHashSet<>();
|
||||
|
@ -88,6 +91,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
this.app = (OsmandApplication) getActivity().getApplication();
|
||||
|
||||
helper = getMyApplication().getFavorites();
|
||||
favouritesAdapter.synchronizeGroups();
|
||||
|
@ -156,6 +160,17 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
|
||||
listView.addFooterView(footerView);
|
||||
}
|
||||
View emptyView = view.findViewById(android.R.id.empty);
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_favorites_day_result : R.drawable.ic_empty_state_favorites_night_result);
|
||||
Button importButton = (Button) emptyView.findViewById(R.id.import_button);
|
||||
importButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
importFavourites();
|
||||
}
|
||||
});
|
||||
listView.setEmptyView(emptyView);
|
||||
listView.setAdapter(favouritesAdapter);
|
||||
setListView(listView);
|
||||
setHasOptionsMenu(true);
|
||||
|
@ -237,6 +252,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
} else if (item.getItemId() == DELETE_ACTION_ID) {
|
||||
deleteFavoritesAction();
|
||||
return true;
|
||||
} else if (item.getItemId() == IMPORT_FAVOURITES_ID) {
|
||||
importFavourites();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -268,6 +286,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
|
||||
|
||||
if (!MenuItemCompat.isActionViewExpanded(mi)) {
|
||||
createMenuItem(menu, IMPORT_FAVOURITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_plus,
|
||||
R.drawable.ic_action_plus, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark,
|
||||
R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
|
||||
if (getSettings().USE_MAP_MARKERS.get()) {
|
||||
|
@ -467,6 +487,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void importFavourites() {
|
||||
((FavoritesActivity) getActivity()).importFavourites();
|
||||
}
|
||||
|
||||
public void shareFavorites(final FavoriteGroup group) {
|
||||
final AsyncTask<Void, Void, Void> exportTask = new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.osmand.plus.GPXUtilities.GPXFile;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -88,6 +89,21 @@ public class GpxImportHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void handleFavouritesImport(Uri uri) {
|
||||
String scheme = uri.getScheme();
|
||||
boolean isFileIntent = "file".equals(scheme);
|
||||
boolean isContentIntent = "content".equals(scheme);
|
||||
boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(uri.getPath()));
|
||||
final boolean saveFile = !isFileIntent || !isOsmandSubdir;
|
||||
String fileName = "";
|
||||
if (isFileIntent) {
|
||||
fileName = new File(uri.getPath()).getName();
|
||||
} else if (isContentIntent) {
|
||||
fileName = getNameFromContentUri(uri);
|
||||
}
|
||||
handleFavouritesImport(uri, fileName, saveFile, false, true);
|
||||
}
|
||||
|
||||
public void handleFileImport(final Uri intentUri, final String fileName, final boolean useImportDir) {
|
||||
final boolean isFileIntent = "file".equals(intentUri.getScheme());
|
||||
final boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
|
||||
|
@ -99,7 +115,7 @@ public class GpxImportHelper {
|
|||
} else if (fileName != null && fileName.endsWith(KMZ_SUFFIX)) {
|
||||
handleKmzImport(intentUri, fileName, saveFile, useImportDir);
|
||||
} else {
|
||||
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir);
|
||||
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,12 +171,12 @@ public class GpxImportHelper {
|
|||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
progress.dismiss();
|
||||
handleResult(result, fileName, save, useImportDir);
|
||||
handleResult(result, fileName, save, useImportDir, false);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir) {
|
||||
private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir, final boolean forceImportFavourites) {
|
||||
new AsyncTask<Void, Void, GPXFile>() {
|
||||
ProgressDialog progress = null;
|
||||
|
||||
|
@ -193,12 +209,12 @@ public class GpxImportHelper {
|
|||
@Override
|
||||
protected void onPostExecute(final GPXFile result) {
|
||||
progress.dismiss();
|
||||
importFavourites(result, fileName, save, useImportDir);
|
||||
importFavourites(result, fileName, save, useImportDir, forceImportFavourites);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void importFavoritesImpl(final GPXFile gpxFile) {
|
||||
private void importFavoritesImpl(final GPXFile gpxFile, final String fileName, final boolean forceImportFavourites) {
|
||||
new AsyncTask<Void, Void, GPXFile>() {
|
||||
ProgressDialog progress = null;
|
||||
|
||||
|
@ -209,7 +225,7 @@ public class GpxImportHelper {
|
|||
|
||||
@Override
|
||||
protected GPXFile doInBackground(Void... nothing) {
|
||||
final List<FavouritePoint> favourites = asFavourites(gpxFile.points);
|
||||
final List<FavouritePoint> favourites = asFavourites(gpxFile.points, fileName, forceImportFavourites);
|
||||
final FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||
for (final FavouritePoint favourite : favourites) {
|
||||
favoritesHelper.deleteFavourite(favourite, false);
|
||||
|
@ -225,6 +241,8 @@ public class GpxImportHelper {
|
|||
progress.dismiss();
|
||||
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
|
||||
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
|
||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
|
||||
activity.startActivity(newIntent);
|
||||
}
|
||||
}.execute();
|
||||
|
@ -277,7 +295,7 @@ public class GpxImportHelper {
|
|||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
progress.dismiss();
|
||||
handleResult(result, name, save, useImportDir);
|
||||
handleResult(result, name, save, useImportDir, false);
|
||||
}
|
||||
|
||||
}.execute();
|
||||
|
@ -322,13 +340,13 @@ public class GpxImportHelper {
|
|||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
progress.dismiss();
|
||||
handleResult(result, name, save, useImportDir);
|
||||
handleResult(result, name, save, useImportDir, false);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void handleResult(final GPXFile result, final String name, final boolean save,
|
||||
final boolean useImportDir) {
|
||||
final boolean useImportDir, boolean forceImportFavourites) {
|
||||
if (result != null) {
|
||||
if (result.warning != null) {
|
||||
Toast.makeText(activity, result.warning, Toast.LENGTH_LONG).show();
|
||||
|
@ -372,6 +390,12 @@ public class GpxImportHelper {
|
|||
})
|
||||
.show();
|
||||
}
|
||||
if (forceImportFavourites) {
|
||||
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
|
||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
newIntent.putExtra(FavoritesActivity.OPEN_MY_PLACES_TAB, true);
|
||||
activity.startActivity(newIntent);
|
||||
}
|
||||
}
|
||||
|
||||
private String saveImport(final GPXFile gpxFile, final String fileName, final boolean useImportDir) {
|
||||
|
@ -467,38 +491,76 @@ public class GpxImportHelper {
|
|||
}
|
||||
|
||||
private void importFavourites(final GPXFile gpxFile, final String fileName, final boolean save,
|
||||
final boolean useImportDir) {
|
||||
final boolean useImportDir, final boolean forceImportFavourites) {
|
||||
if (gpxFile == null || gpxFile.points == null || gpxFile.points.size() == 0) {
|
||||
handleResult(gpxFile, fileName, save, useImportDir);
|
||||
return;
|
||||
}
|
||||
final DialogInterface.OnClickListener importFavouritesListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
importFavoritesImpl(gpxFile);
|
||||
break;
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
handleResult(gpxFile, fileName, save, useImportDir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
if (forceImportFavourites) {
|
||||
final DialogInterface.OnClickListener importAsTrackListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
handleResult(gpxFile, fileName, save, useImportDir, true);
|
||||
break;
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
dialog.dismiss();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.shared_string_import2osmand)
|
||||
.setMessage(R.string.import_file_favourites)
|
||||
.setPositiveButton(R.string.shared_string_import, importFavouritesListener)
|
||||
.setNegativeButton(R.string.shared_string_save, importFavouritesListener)
|
||||
.show();
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.import_track)
|
||||
.setMessage(activity.getString(R.string.import_track_desc, fileName))
|
||||
.setPositiveButton(R.string.shared_string_import, importAsTrackListener)
|
||||
.setNegativeButton(R.string.shared_string_cancel, importAsTrackListener)
|
||||
.show();
|
||||
return;
|
||||
} else {
|
||||
handleResult(gpxFile, fileName, save, useImportDir, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (forceImportFavourites) {
|
||||
importFavoritesImpl(gpxFile, fileName, true);
|
||||
} else {
|
||||
final DialogInterface.OnClickListener importFavouritesListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
importFavoritesImpl(gpxFile, fileName, false);
|
||||
break;
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
handleResult(gpxFile, fileName, save, useImportDir, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.shared_string_import2osmand)
|
||||
.setMessage(R.string.import_file_favourites)
|
||||
.setPositiveButton(R.string.shared_string_import, importFavouritesListener)
|
||||
.setNegativeButton(R.string.shared_string_save, importFavouritesListener)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
private List<FavouritePoint> asFavourites(final List<GPXUtilities.WptPt> wptPts) {
|
||||
private List<FavouritePoint> asFavourites(final List<GPXUtilities.WptPt> wptPts, String fileName, boolean forceImportFavourites) {
|
||||
final List<FavouritePoint> favourites = new ArrayList<>();
|
||||
for (GPXUtilities.WptPt p : wptPts) {
|
||||
if (p.name != null) {
|
||||
final String fpCat = (p.category != null) ? p.category : "";
|
||||
final String fpCat;
|
||||
if (p.category == null) {
|
||||
if (forceImportFavourites) {
|
||||
fpCat = fileName;
|
||||
} else {
|
||||
fpCat = "";
|
||||
}
|
||||
} else {
|
||||
fpCat = p.category;
|
||||
}
|
||||
final FavouritePoint fp = new FavouritePoint(p.lat, p.lon, p.name, fpCat);
|
||||
if (p.desc != null) {
|
||||
fp.setDescription(p.desc);
|
||||
|
|
|
@ -327,6 +327,17 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
footerView = inflater.inflate(R.layout.list_shadow_footer, null, false);
|
||||
listView.addFooterView(footerView);
|
||||
View emptyView = v.findViewById(android.R.id.empty);
|
||||
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
|
||||
emptyImageView.setImageResource(app.getSettings().isLightContent() ? R.drawable.ic_empty_state_trip_day_result : R.drawable.ic_empty_state_trip_night_result);
|
||||
Button importButton = (Button) emptyView.findViewById(R.id.import_button);
|
||||
importButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
addTrack();
|
||||
}
|
||||
});
|
||||
listView.setEmptyView(emptyView);
|
||||
if (this.adapter != null) {
|
||||
listView.setAdapter(this.adapter);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ import java.util.List;
|
|||
public class FavoritesActivity extends TabActivity {
|
||||
|
||||
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006;
|
||||
private static final int IMPORT_FAVOURITES_REQUEST = 1007;
|
||||
|
||||
public static final String OPEN_FAVOURITES_TAB = "open_favourites_tab";
|
||||
public static final String OPEN_MY_PLACES_TAB = "open_my_places_tab";
|
||||
|
||||
public static final int GPX_TAB = R.string.shared_string_my_tracks;
|
||||
public static final int FAV_TAB = R.string.shared_string_my_favorites;
|
||||
|
@ -67,6 +71,16 @@ public class FavoritesActivity extends TabActivity {
|
|||
List<TabItem> mTabs = getTabItems();
|
||||
setTabs(mTabs);
|
||||
// setupHomeButton();
|
||||
|
||||
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
if (intent.hasExtra(OPEN_FAVOURITES_TAB) && intent.getBooleanExtra(OPEN_FAVOURITES_TAB, false)) {
|
||||
mViewPager.setCurrentItem(0, false);
|
||||
} else if (intent.hasExtra(OPEN_MY_PLACES_TAB) && intent.getBooleanExtra(OPEN_MY_PLACES_TAB, false)) {
|
||||
mViewPager.setCurrentItem(1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
|
@ -76,6 +90,13 @@ public class FavoritesActivity extends TabActivity {
|
|||
startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public void importFavourites() {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.setType("*/*");
|
||||
startActivityForResult(intent, IMPORT_FAVOURITES_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == OPEN_GPX_DOCUMENT_REQUEST && resultCode == Activity.RESULT_OK) {
|
||||
|
@ -101,6 +122,11 @@ public class FavoritesActivity extends TabActivity {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (requestCode == IMPORT_FAVOURITES_REQUEST && resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
Uri uri = data.getData();
|
||||
gpxImportHelper.handleFavouritesImport(uri);
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
@ -135,22 +161,9 @@ public class FavoritesActivity extends TabActivity {
|
|||
}
|
||||
|
||||
private List<TabItem> getTabItems() {
|
||||
File[] lf = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.GPX_INDEX_DIR).listFiles();
|
||||
boolean hasGpx = false;
|
||||
if (lf != null) {
|
||||
for (File t : lf) {
|
||||
if (t.isDirectory() || (t.getName().toLowerCase().endsWith(".gpx"))) {
|
||||
hasGpx = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<TabItem> mTabs = new ArrayList<>();
|
||||
mTabs.add(getTabIndicator(FAV_TAB, FavoritesTreeFragment.class));
|
||||
if (hasGpx) {
|
||||
mTabs.add(getTabIndicator(GPX_TAB, AvailableGPXFragment.class));
|
||||
}
|
||||
mTabs.add(getTabIndicator(GPX_TAB, AvailableGPXFragment.class));
|
||||
OsmandPlugin.addMyPlacesTabPlugins(this, mTabs, getIntent());
|
||||
return mTabs;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue