blob: f7e6bc2cc70c086062fa221771ad61b6ff8f7535 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package com.mapswithme.maps.bookmarks;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
import com.mapswithme.util.statistics.Statistics;
public class ShowOnMapCatalogCategoryFragment extends DialogFragment
{
public static final String TAG = ShowOnMapCatalogCategoryFragment.class.getCanonicalName();
static final String ARGS_CATEGORY = "downloaded_category";
@SuppressWarnings("NullableProblems")
@NonNull
private BookmarkCategory mCategory;
@Override
public void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle args = getArguments();
mCategory = getCategoryOrThrow(args);
}
@NonNull
private BookmarkCategory getCategoryOrThrow(@Nullable Bundle args)
{
BookmarkCategory category;
if (args == null || ((category = args.getParcelable(ARGS_CATEGORY)) == null))
throw new IllegalArgumentException("Category not found");
return category;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable
Bundle savedInstanceState)
{
View root = inflater.inflate(R.layout.fragment_show_on_map_catalog_category, container, false);
View acceptBtn = root.findViewById(R.id.show_on_map_accept_btn);
acceptBtn.setOnClickListener(v -> onAccepted());
root.setOnClickListener(view -> onDeclined());
return root;
}
private void onDeclined()
{
Statistics.INSTANCE.trackDownloadBookmarkDialog(Statistics.ParamValue.NOT_NOW);
dismissAllowingStateLoss();
}
private void onAccepted()
{
Statistics.INSTANCE.trackDownloadBookmarkDialog(Statistics.ParamValue.VIEW_ON_MAP);
Intent result = new Intent().putExtra(BookmarksCatalogActivity.EXTRA_DOWNLOADED_CATEGORY,
mCategory);
getActivity().setResult(Activity.RESULT_OK, result);
dismissAllowingStateLoss();
getActivity().finish();
}
@Override
public void onCancel(DialogInterface dialog)
{
super.onCancel(dialog);
Statistics.INSTANCE.trackDownloadBookmarkDialog(Statistics.ParamValue.CLICK_OUTSIDE);
}
void setCategory(@NonNull BookmarkCategory category)
{
mCategory = category;
}
@NonNull
public static ShowOnMapCatalogCategoryFragment newInstance(@NonNull BookmarkCategory category)
{
Bundle args = new Bundle();
args.putParcelable(ARGS_CATEGORY, category);
ShowOnMapCatalogCategoryFragment fragment = new ShowOnMapCatalogCategoryFragment();
fragment.setArguments(args);
return fragment;
}
}
|