|
1 package org.hedgewars.hedgeroid.Downloader; |
|
2 |
|
3 import org.hedgewars.hedgeroid.R; |
|
4 |
|
5 import android.app.AlertDialog; |
|
6 import android.app.AlertDialog.Builder; |
|
7 import android.app.Dialog; |
|
8 import android.content.DialogInterface; |
|
9 import android.content.DialogInterface.OnClickListener; |
|
10 import android.content.Intent; |
|
11 import android.os.Bundle; |
|
12 import android.support.v4.app.DialogFragment; |
|
13 |
|
14 public class DownloadDialogFragment extends DialogFragment { |
|
15 |
|
16 public static final int NUM_ALREADYDOWNLOADED = 0; |
|
17 public static final int NUM_AREYOUSURE = 1; |
|
18 |
|
19 private final static String BUNDLE_TASK = "task"; |
|
20 |
|
21 static DownloadDialogFragment newInstance(DownloadPackage task){ |
|
22 DownloadDialogFragment dialog = new DownloadDialogFragment(); |
|
23 |
|
24 Bundle args = new Bundle(); |
|
25 args.putParcelable(DownloadDialogFragment.BUNDLE_TASK, task); |
|
26 dialog.setArguments(args); |
|
27 |
|
28 return dialog; |
|
29 } |
|
30 |
|
31 public Dialog onCreateDialog(Bundle savedInstanceState){ |
|
32 DownloadPackage task = (DownloadPackage)getArguments().getParcelable(DownloadDialogFragment.BUNDLE_TASK); |
|
33 |
|
34 Builder builder = new AlertDialog.Builder(getActivity()); |
|
35 |
|
36 switch(task.getStatus()){ |
|
37 case CURRENTVERSION: |
|
38 case NEWERVERSION: |
|
39 builder.setMessage(R.string.download_areyousure); |
|
40 break; |
|
41 case OLDERVERSION: |
|
42 builder.setMessage(R.string.download_alreadydownloaded); |
|
43 break; |
|
44 } |
|
45 |
|
46 DownloadClicker clicker = new DownloadClicker(task); |
|
47 builder.setPositiveButton(android.R.string.yes, clicker); |
|
48 builder.setNegativeButton(android.R.string.no, clicker); |
|
49 |
|
50 return builder.create(); |
|
51 } |
|
52 |
|
53 class DownloadClicker implements OnClickListener{ |
|
54 |
|
55 DownloadPackage task = null; |
|
56 |
|
57 public DownloadClicker(DownloadPackage _task){ |
|
58 task = _task; |
|
59 } |
|
60 |
|
61 public void onClick(DialogInterface dialog, int which) { |
|
62 if(which == Dialog.BUTTON_POSITIVE){ |
|
63 Intent i = new Intent(getActivity(), DownloadFragment.class); |
|
64 i.putExtra(DownloadFragment.EXTRA_TASK, task); |
|
65 getActivity().startActivity(i); |
|
66 } |
|
67 } |
|
68 } |
|
69 } |