project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Downloader/DownloadDialogFragment.java
author unc0rr
Mon, 19 Nov 2018 22:26:47 +0100
changeset 14256 fa2e3f123a09
parent 10017 de822cd3df3a
permissions -rw-r--r--
Unify fpcrtl_pchar2astr look with fpcrtl_pchar2str
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     3
 * Copyright (c) 2011-2012 Richard Deurwaarder <xeli@xelification.com>
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     5
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     6
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     8
 * of the License, or (at your option) any later version.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    13
 * GNU General Public License for more details.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    15
 * You should have received a copy of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    16
 * along with this program; if not, write to the Free Software
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 6566
diff changeset
    19
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    20
package org.hedgewars.hedgeroid.Downloader;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    21
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    22
import org.hedgewars.hedgeroid.R;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    23
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    24
import android.app.AlertDialog;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    25
import android.app.AlertDialog.Builder;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    26
import android.app.Dialog;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    27
import android.content.DialogInterface;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    28
import android.content.DialogInterface.OnClickListener;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    29
import android.content.Intent;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    30
import android.os.Bundle;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    31
import android.support.v4.app.DialogFragment;
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    32
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    33
public class DownloadDialogFragment extends DialogFragment {
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    34
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    35
    public static final int NUM_ALREADYDOWNLOADED = 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    36
    public static final int NUM_AREYOUSURE = 1;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    37
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    38
    private final static String BUNDLE_TASK = "task";
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    39
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    40
    static DownloadDialogFragment newInstance(DownloadPackage task){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    41
        DownloadDialogFragment dialog = new DownloadDialogFragment();
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    42
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    43
        Bundle args = new Bundle();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    44
        args.putParcelable(DownloadDialogFragment.BUNDLE_TASK, task);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    45
        dialog.setArguments(args);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    46
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    47
        return dialog;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    49
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
    public Dialog onCreateDialog(Bundle savedInstanceState){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    51
        DownloadPackage task = (DownloadPackage)getArguments().getParcelable(DownloadDialogFragment.BUNDLE_TASK);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    52
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
        Builder builder = new AlertDialog.Builder(getActivity());
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    54
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
        switch(task.getStatus()){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
        case CURRENTVERSION:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
        case NEWERVERSION:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    58
            builder.setMessage(R.string.download_areyousure);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
            break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
        case OLDERVERSION:
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
            builder.setMessage(R.string.download_alreadydownloaded);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
            break;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
        }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    64
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
        DownloadClicker clicker = new DownloadClicker(task);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
        builder.setPositiveButton(android.R.string.yes, clicker);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
        builder.setNegativeButton(android.R.string.no, clicker);
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    68
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
        return builder.create();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    71
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
    class DownloadClicker implements OnClickListener{
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    73
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    74
        DownloadPackage task = null;
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    75
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    76
        public DownloadClicker(DownloadPackage _task){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    77
            task = _task;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
        }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    79
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    80
        public void onClick(DialogInterface dialog, int which) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    81
            if(which == Dialog.BUTTON_POSITIVE){
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
                Intent i = new Intent(getActivity(), DownloadListActivity.class);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    83
                i.putExtra(DownloadFragment.EXTRA_TASK, task);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    84
                getActivity().startActivity(i);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    85
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    86
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
    }
6350
41b0a9955c47 new download manager \o/
Xeli
parents:
diff changeset
    88
}