1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
import android.graphics.Bitmap;
|
24
|
import android.graphics.Color;
|
25
|
import android.util.TypedValue;
|
26
|
import android.view.View;
|
27
|
import android.widget.Button;
|
28
|
import android.widget.ImageView;
|
29
|
import android.widget.LinearLayout;
|
30
|
import android.widget.ProgressBar;
|
31
|
import android.widget.TextView;
|
32
|
|
33
|
import org.distorted.main.R;
|
34
|
import org.distorted.external.RubikNetwork;
|
35
|
import org.distorted.external.RubikUpdates;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
public class RubikDialogUpdateView implements RubikNetwork.Downloadee
|
40
|
{
|
41
|
private ImageView mIcon;
|
42
|
private RubikUpdates.UpdateInfo mInfo;
|
43
|
private ProgressBar mBar;
|
44
|
private Button mButton;
|
45
|
private TextView mDescription;
|
46
|
|
47
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
48
|
|
49
|
public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding,
|
50
|
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt )
|
51
|
{
|
52
|
mInfo = info;
|
53
|
final RubikNetwork.Downloadee downloadee = this;
|
54
|
View view = act.getLayoutInflater().inflate(R.layout.dialog_updates_pane, null);
|
55
|
TextView title = view.findViewById(R.id.updates_pane_title);
|
56
|
title.setText(info.mObjectLongName);
|
57
|
mDescription = view.findViewById(R.id.updates_pane_description);
|
58
|
mDescription.setText(info.mDescription);
|
59
|
|
60
|
mIcon = view.findViewById(R.id.updates_pane_image);
|
61
|
mIcon.setImageResource(R.drawable.unknown_icon);
|
62
|
|
63
|
view.setLayoutParams(pView);
|
64
|
|
65
|
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
66
|
mDescription.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
67
|
|
68
|
title.setLayoutParams(pText);
|
69
|
mDescription.setLayoutParams(pText);
|
70
|
|
71
|
view.setPadding(padding,padding,padding,padding);
|
72
|
|
73
|
mBar = view.findViewById(R.id.updates_pane_bar);
|
74
|
mButton = view.findViewById(R.id.updates_pane_button);
|
75
|
|
76
|
if( info.mPercent>=100 )
|
77
|
{
|
78
|
mBar.setVisibility(View.GONE);
|
79
|
mButton.setOnClickListener( new View.OnClickListener()
|
80
|
{
|
81
|
@Override
|
82
|
public void onClick(View v)
|
83
|
{
|
84
|
startDownload();
|
85
|
RubikNetwork network = RubikNetwork.getInstance();
|
86
|
network.downloadJSON(info,downloadee);
|
87
|
}
|
88
|
});
|
89
|
|
90
|
mButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
|
91
|
mButton.setLayoutParams(pButt);
|
92
|
mBar.setLayoutParams(pButt);
|
93
|
}
|
94
|
else
|
95
|
{
|
96
|
mButton.setVisibility(View.GONE);
|
97
|
mBar.setLayoutParams(pButt);
|
98
|
mBar.setProgress(info.mPercent);
|
99
|
}
|
100
|
|
101
|
return view;
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
void setIcon(Bitmap icon)
|
107
|
{
|
108
|
mIcon.setImageBitmap(icon);
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
private void startDownload()
|
114
|
{
|
115
|
mDescription.setText(R.string.downloading);
|
116
|
mBar.setProgress(20);
|
117
|
mButton.setVisibility(View.GONE);
|
118
|
mBar.setVisibility(View.VISIBLE);
|
119
|
}
|
120
|
|
121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122
|
|
123
|
public void jsonDownloaded()
|
124
|
{
|
125
|
if( mInfo.mUpdateObject && mInfo.mObjectStream==null )
|
126
|
{
|
127
|
mDescription.setTextColor(Color.parseColor("#ff0000"));
|
128
|
mDescription.setText(R.string.networkError);
|
129
|
}
|
130
|
else
|
131
|
{
|
132
|
mBar.setProgress(50);
|
133
|
mDescription.setText(R.string.installing);
|
134
|
}
|
135
|
}
|
136
|
}
|