|
1 | 1 | package org.open311.android.fragments; |
2 | 2 |
|
3 | 3 |
|
| 4 | +import android.content.SharedPreferences; |
4 | 5 | import android.os.Bundle; |
5 | 6 | import android.support.v4.app.Fragment; |
| 7 | +import android.text.Html; |
6 | 8 | import android.util.Log; |
7 | 9 | import android.view.LayoutInflater; |
8 | 10 | import android.view.View; |
9 | 11 | import android.view.ViewGroup; |
| 12 | +import android.widget.TextView; |
10 | 13 |
|
| 14 | +import org.codeforamerica.open311.facade.data.City; |
| 15 | +import org.open311.android.MainActivity; |
11 | 16 | import org.open311.android.R; |
12 | 17 |
|
| 18 | +import static org.open311.android.helpers.Utils.getSettings; |
| 19 | + |
13 | 20 | /** |
14 | 21 | * Policy {@link Fragment} subclass. |
15 | 22 | */ |
16 | 23 | public class PolicyFragment extends Fragment { |
17 | 24 | private static final String LOG_TAG = "PolicyFragment"; |
| 25 | + private SharedPreferences settings; |
18 | 26 |
|
19 | 27 | public PolicyFragment() { |
20 | | - // Required empty public constructor |
| 28 | + |
21 | 29 | } |
22 | 30 |
|
23 | 31 | @Override |
24 | 32 | public void onCreate(Bundle savedInstanceState) { |
25 | 33 | super.onCreate(savedInstanceState); |
| 34 | + settings = getSettings(getActivity()); |
| 35 | + |
26 | 36 | } |
27 | 37 |
|
28 | 38 | @Override |
29 | 39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
30 | 40 | Log.d(LOG_TAG, "onCreateView"); |
31 | 41 | // Inflate the layout for this fragment |
32 | | - return inflater.inflate(R.layout.fragment_policy, container, false); |
| 42 | + View view = inflater.inflate(R.layout.fragment_policy, container, false); |
| 43 | + TextView introTitle = (TextView) view.findViewById(R.id.policy_intro_title); |
| 44 | + TextView introText = (TextView) view.findViewById(R.id.policy_intro_text); |
| 45 | + City currentCity = ((MainActivity) getActivity()).getCurrentCity(); |
| 46 | + introTitle.setText(settings.getString("current_city", getString(R.string.policy_intro_title))); |
| 47 | + |
| 48 | + |
| 49 | + introText.setText(currentCity.getDescription()); |
| 50 | + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { |
| 51 | + if (currentCity.getDescription() != null) { |
| 52 | + introText.setText(Html.fromHtml(currentCity.getDescription().replace("\n","<br />"), Html.FROM_HTML_MODE_LEGACY)); |
| 53 | + } else { |
| 54 | + introText.setText(Html.fromHtml(getString(R.string.policy_intro_text).replace("\n","<br />"), Html.FROM_HTML_MODE_LEGACY)); |
| 55 | + } |
| 56 | + } else { |
| 57 | + if (currentCity.getDescription() != null) { |
| 58 | + introText.setText(Html.fromHtml(currentCity.getDescription().replace("\n","<br />"))); |
| 59 | + } else { |
| 60 | + introText.setText(Html.fromHtml(getString(R.string.policy_intro_text).replace("\n","<br />"))); |
| 61 | + } |
| 62 | + } |
| 63 | + return view; |
33 | 64 | } |
34 | 65 |
|
35 | 66 | } |
0 commit comments