Project

General

Profile

Download (5.37 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogUpdateView.java @ 46be3ddf

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.network.RubikNetwork;
35
import org.distorted.network.RubikUpdates;
36

    
37
import java.io.InputStream;
38

    
39
import static android.view.View.GONE;
40
import static android.view.View.VISIBLE;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class RubikDialogUpdateView implements RubikNetwork.Downloadee
45
  {
46
  private ImageView mIcon;
47
  private RubikUpdates.UpdateInfo mInfo;
48
  private ProgressBar mBar;
49
  private Button mButton;
50
  private TextView mDescription;
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding,
55
                         LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt )
56
    {
57
    mInfo = info;
58
    final RubikNetwork.Downloadee downloadee = this;
59
    View view = act.getLayoutInflater().inflate(R.layout.dialog_updates_pane, null);
60
    TextView title = view.findViewById(R.id.updates_pane_title);
61
    title.setText(info.mObjectLongName);
62
    mDescription = view.findViewById(R.id.updates_pane_description);
63
    mDescription.setText(info.mDescription);
64

    
65
    mIcon = view.findViewById(R.id.updates_pane_image);
66
    mIcon.setImageResource(R.drawable.unknown_icon);
67

    
68
    view.setLayoutParams(pView);
69

    
70
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
71
    mDescription.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
72

    
73
    title.setLayoutParams(pText);
74
    mDescription.setLayoutParams(pText);
75

    
76
    view.setPadding(padding,padding,padding,padding);
77

    
78
    mBar    = view.findViewById(R.id.updates_pane_bar);
79
    mButton = view.findViewById(R.id.updates_pane_button);
80

    
81
    if( info.mPercent>=100 )
82
      {
83
      mBar.setVisibility(GONE);
84
      mButton.setOnClickListener( new View.OnClickListener()
85
        {
86
        @Override
87
        public void onClick(View v)
88
          {
89
          startDownload();
90
          RubikNetwork network = RubikNetwork.getInstance();
91
          network.downloadJSON(info,downloadee);
92
          }
93
        });
94

    
95
      mButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize);
96
      mButton.setLayoutParams(pButt);
97
      mBar.setLayoutParams(pButt);
98
      }
99
    else
100
      {
101
      mButton.setVisibility(GONE);
102
      mBar.setLayoutParams(pButt);
103
      mBar.setProgress(info.mPercent);
104
      }
105

    
106
    return view;
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  void setIcon(Bitmap icon)
112
    {
113
    mIcon.setImageBitmap(icon);
114
    }
115

    
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
  }
(20-20/21)