Blame view

app/src/main/java/com/sunvote/xpadapp/fragments/SigninFragment.java 3.58 KB
27983dbe   孙向锦   project init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  package com.sunvote.xpadapp.fragments;
  
  import com.sunvote.xpadapp.MainActivity;
  import com.sunvote.xpadapp.R;
  import com.sunvote.xpadapp.base.BaseFragment;
  import com.sunvote.xpadapp.db.DBManager;
  import com.sunvote.xpadapp.utils.SharedPreferencesUtil;
  import com.sunvote.xpadcomm.XPadApi;
  import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo;
  
  import android.app.Fragment;
  import android.app.ProgressDialog;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class SigninFragment extends BaseFragment {
  	private TextView tv;
  	private Button btnSignin;
  	private VoteInfo voteInfo;
  	View bgView;
  	
  	public void setInfo(VoteInfo info) {
  		voteInfo = info;
  	}
  	 
  	@Override
  	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  		Log.d("SigninFragment", "onCreateView");
  		View view = inflater.inflate(R.layout.fragment_signin, container, false);
  		view.setOnClickListener(new OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				;
  			}
  		});
  		bgView = view.findViewById(R.id.signin_bg);
  
  		tv = (TextView)view.findViewById(R.id.signin_title);
  		btnSignin = (Button)view.findViewById(R.id.signin_btnSign);
  		btnSignin.setEnabled(false);
  		btnSignin.setOnClickListener(new OnClickListener() {
  			
  			@Override
  			public void onClick(View v) {
  				tv.setText(getString(R.string.signining));
  				 MainActivity mact = (MainActivity)getActivity();
  				 mact.presenter.submitVote( XPadApi.AnsType_Single,"1");
  				 btnSignin.setEnabled(false);
  				 
  			}
  		});
  		 
  		if(voteInfo!=null){
  			onVoteEvent(voteInfo);
  		}
  		checkIsVoted();
  		return view;
  	}
  	
  	@Override 
  	public void onVoteEvent( VoteInfo info) {
  		 if(info.mode ==XPadApi.VoteType_Signin){
  			 btnSignin.setEnabled(true);
  			 
  		 }else if(info.mode == XPadApi.VoteType_Stop){
  			 btnSignin.setEnabled(false);
  			 
  		 }
  	}
  
  	/**
  	 * 0:已签到,1:未签到
  	 */
  	private void saveVoteInfo(String voteValue){
  		SharedPreferencesUtil.saveData(getActivity(),DATAPOS,Integer.valueOf(voteInfo.dataPos));
  		SharedPreferencesUtil.saveData(getActivity(),VOTEMODE,Integer.valueOf(voteInfo.mode));
  		SharedPreferencesUtil.saveData(getActivity(),VOTEVALUES,voteValue);
  	}
  
  	private void checkIsVoted(){
  		Integer datapos = (Integer) SharedPreferencesUtil.getData(getActivity(),DATAPOS,Integer.valueOf(-1));
  		Integer votemode = (Integer) SharedPreferencesUtil.getData(getActivity(),VOTEMODE,Integer.valueOf(-1));
  		String voteValues = (String) SharedPreferencesUtil.getData(getActivity(),VOTEVALUES,"");
  
  		if(datapos.intValue() == voteInfo.dataPos && votemode.intValue() == voteInfo.mode && voteValues.length()>0){
  			if(voteValues.equals("0")){
  				tv.setText(getString(R.string.signined));
  				btnSignin.setEnabled(false);
  				((MainActivity)getActivity()).myHandler.sendEmptyMessageDelayed(MainActivity.MSG_DELAY_TO_VIEW,2000);
  			}else{
  				tv.setText(getString(R.string.please_signin));
  				btnSignin.setEnabled(true);
  			}
  		}
  	}
  
  	@Override
  	public void onVoteSubmitSuccess() {
  		tv.setText(getString(R.string.signined));
  		btnSignin.setEnabled(false);
  		saveVoteInfo("0");
  	//	bgView.setBackgroundColor(0xFF009966);
   
  		((MainActivity)getActivity()).myHandler.sendEmptyMessageDelayed(MainActivity.MSG_DELAY_TO_VIEW,2000);
  	}
  	@Override
  	public void onVoteSubmitError() {
  		super.onVoteSubmitError();
  		tv.setText(getString(R.string.please_signin));
  		btnSignin.setEnabled(true);
  		saveVoteInfo("1");
  	}
  	
  }