1 |
9c39179e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2022 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.dialogs;
|
21 |
|
|
|
22 |
|
|
import android.app.Activity;
|
23 |
b88cdd91
|
Leszek Koltunski
|
import android.graphics.Bitmap;
|
24 |
46be3ddf
|
Leszek Koltunski
|
import android.graphics.Color;
|
25 |
c651024f
|
Leszek Koltunski
|
import android.util.TypedValue;
|
26 |
9c39179e
|
Leszek Koltunski
|
import android.view.View;
|
27 |
|
|
import android.widget.Button;
|
28 |
7bee6064
|
Leszek Koltunski
|
import android.widget.ImageView;
|
29 |
c651024f
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
30 |
2c9ab085
|
Leszek Koltunski
|
import android.widget.ProgressBar;
|
31 |
9c39179e
|
Leszek Koltunski
|
import android.widget.TextView;
|
32 |
|
|
|
33 |
|
|
import org.distorted.main.R;
|
34 |
46be3ddf
|
Leszek Koltunski
|
import org.distorted.network.RubikNetwork;
|
35 |
9c39179e
|
Leszek Koltunski
|
import org.distorted.network.RubikUpdates;
|
36 |
|
|
|
37 |
46be3ddf
|
Leszek Koltunski
|
import java.io.InputStream;
|
38 |
|
|
|
39 |
9fde123a
|
Leszek Koltunski
|
import static android.view.View.GONE;
|
40 |
46be3ddf
|
Leszek Koltunski
|
import static android.view.View.VISIBLE;
|
41 |
9fde123a
|
Leszek Koltunski
|
|
42 |
9c39179e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
|
|
|
44 |
46be3ddf
|
Leszek Koltunski
|
public class RubikDialogUpdateView implements RubikNetwork.Downloadee
|
45 |
9c39179e
|
Leszek Koltunski
|
{
|
46 |
b88cdd91
|
Leszek Koltunski
|
private ImageView mIcon;
|
47 |
46be3ddf
|
Leszek Koltunski
|
private RubikUpdates.UpdateInfo mInfo;
|
48 |
|
|
private ProgressBar mBar;
|
49 |
|
|
private Button mButton;
|
50 |
|
|
private TextView mDescription;
|
51 |
9c39179e
|
Leszek Koltunski
|
|
52 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53 |
|
|
|
54 |
2c9ab085
|
Leszek Koltunski
|
public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding,
|
55 |
06ba394a
|
Leszek Koltunski
|
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt )
|
56 |
9c39179e
|
Leszek Koltunski
|
{
|
57 |
46be3ddf
|
Leszek Koltunski
|
mInfo = info;
|
58 |
|
|
final RubikNetwork.Downloadee downloadee = this;
|
59 |
9fde123a
|
Leszek Koltunski
|
View view = act.getLayoutInflater().inflate(R.layout.dialog_updates_pane, null);
|
60 |
2c9ab085
|
Leszek Koltunski
|
TextView title = view.findViewById(R.id.updates_pane_title);
|
61 |
9c39179e
|
Leszek Koltunski
|
title.setText(info.mObjectLongName);
|
62 |
46be3ddf
|
Leszek Koltunski
|
mDescription = view.findViewById(R.id.updates_pane_description);
|
63 |
|
|
mDescription.setText(info.mDescription);
|
64 |
9c39179e
|
Leszek Koltunski
|
|
65 |
b88cdd91
|
Leszek Koltunski
|
mIcon = view.findViewById(R.id.updates_pane_image);
|
66 |
|
|
mIcon.setImageResource(R.drawable.unknown_icon);
|
67 |
7bee6064
|
Leszek Koltunski
|
|
68 |
2c9ab085
|
Leszek Koltunski
|
view.setLayoutParams(pView);
|
69 |
c651024f
|
Leszek Koltunski
|
|
70 |
|
|
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
71 |
46be3ddf
|
Leszek Koltunski
|
mDescription.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
72 |
c651024f
|
Leszek Koltunski
|
|
73 |
|
|
title.setLayoutParams(pText);
|
74 |
46be3ddf
|
Leszek Koltunski
|
mDescription.setLayoutParams(pText);
|
75 |
c651024f
|
Leszek Koltunski
|
|
76 |
2c9ab085
|
Leszek Koltunski
|
view.setPadding(padding,padding,padding,padding);
|
77 |
|
|
|
78 |
46be3ddf
|
Leszek Koltunski
|
mBar = view.findViewById(R.id.updates_pane_bar);
|
79 |
|
|
mButton = view.findViewById(R.id.updates_pane_button);
|
80 |
2c9ab085
|
Leszek Koltunski
|
|
81 |
9fde123a
|
Leszek Koltunski
|
if( info.mPercent>=100 )
|
82 |
|
|
{
|
83 |
46be3ddf
|
Leszek Koltunski
|
mBar.setVisibility(GONE);
|
84 |
|
|
mButton.setOnClickListener( new View.OnClickListener()
|
85 |
2c9ab085
|
Leszek Koltunski
|
{
|
86 |
|
|
@Override
|
87 |
|
|
public void onClick(View v)
|
88 |
|
|
{
|
89 |
46be3ddf
|
Leszek Koltunski
|
startDownload();
|
90 |
|
|
RubikNetwork network = RubikNetwork.getInstance();
|
91 |
|
|
network.downloadJSON(info,downloadee);
|
92 |
2c9ab085
|
Leszek Koltunski
|
}
|
93 |
|
|
});
|
94 |
|
|
|
95 |
46be3ddf
|
Leszek Koltunski
|
mButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
96 |
|
|
mButton.setLayoutParams(pButt);
|
97 |
|
|
mBar.setLayoutParams(pButt);
|
98 |
2c9ab085
|
Leszek Koltunski
|
}
|
99 |
|
|
else
|
100 |
|
|
{
|
101 |
46be3ddf
|
Leszek Koltunski
|
mButton.setVisibility(GONE);
|
102 |
|
|
mBar.setLayoutParams(pButt);
|
103 |
|
|
mBar.setProgress(info.mPercent);
|
104 |
2c9ab085
|
Leszek Koltunski
|
}
|
105 |
99b8a069
|
Leszek Koltunski
|
|
106 |
2c9ab085
|
Leszek Koltunski
|
return view;
|
107 |
9c39179e
|
Leszek Koltunski
|
}
|
108 |
b88cdd91
|
Leszek Koltunski
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
|
|
|
111 |
|
|
void setIcon(Bitmap icon)
|
112 |
|
|
{
|
113 |
|
|
mIcon.setImageBitmap(icon);
|
114 |
|
|
}
|
115 |
46be3ddf
|
Leszek Koltunski
|
|
116 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
private void startDownload()
|
119 |
|
|
{
|
120 |
|
|
mDescription.setText(R.string.downloading);
|
121 |
|
|
mBar.setProgress(20);
|
122 |
|
|
mButton.setVisibility(GONE);
|
123 |
|
|
mBar.setVisibility(VISIBLE);
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127 |
|
|
|
128 |
|
|
public void jsonDownloaded()
|
129 |
|
|
{
|
130 |
|
|
if( mInfo.mUpdateObject && mInfo.mObjectStream==null )
|
131 |
|
|
{
|
132 |
|
|
mDescription.setTextColor(Color.parseColor("#ff0000"));
|
133 |
|
|
mDescription.setText(R.string.networkError);
|
134 |
|
|
}
|
135 |
|
|
else
|
136 |
|
|
{
|
137 |
|
|
mBar.setProgress(50);
|
138 |
|
|
mDescription.setText(R.string.installing);
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
9c39179e
|
Leszek Koltunski
|
}
|