From 75e79c3ed9ee9809c1f92b67c82151aea1b24b4a Mon Sep 17 00:00:00 2001 From: Igor Sofiychenko Date: Mon, 23 Nov 2015 20:05:43 +0200 Subject: [PATCH] 0.9.9 Release Added signup, tests checking --- .idea/dbnavigator.xml | 2 +- .idea/gradle.xml | 2 +- .idea/inspectionProfiles/Project_Default.xml | 5 ++ app/app.iml | 25 ++---- app/src/main/AndroidManifest.xml | 18 ++-- .../com/asoluter/litest/AnsverActivity.java | 35 ++++++++ .../litest/Ansvers/AnsversDatabase.java | 9 -- .../asoluter/litest/ChooseTestActivity.java | 76 +++++++++++++--- .../com/asoluter/litest/LoginActivity.java | 9 +- .../asoluter/litest/Objects/AnsObject.java | 34 +++++++- .../com/asoluter/litest/Objects/Pair.java | 29 +++++++ .../com/asoluter/litest/Objects/RegData.java | 38 ++++++-- .../com/asoluter/litest/Objects/Strings.java | 2 + .../Services/Broadcasts/Broadcasts.java | 2 + .../litest/Services/DBHelper/DBHelper.java | 5 +- .../litest/Services/ServerRequest.java | 56 +++++++++++- .../com/asoluter/litest/SettingsActivity.java | 4 +- .../com/asoluter/litest/SignupActivity.java | 86 ++++++++++++++++++- .../com/asoluter/litest/TestActivity.java | 38 +++++++- .../com/asoluter/litest/Tests/TestsCover.java | 11 ++- app/src/main/res/layout/activity_ansver.xml | 25 ++++++ app/src/main/res/layout/activity_signup.xml | 6 +- app/src/main/res/layout/activity_test.xml | 56 +++++++----- app/src/main/res/layout/content_ansver.xml | 33 +++++++ app/src/main/res/menu/global.xml | 3 +- app/src/main/res/menu/menu_choose_test.xml | 4 +- app/src/main/res/menu/menu_login.xml | 3 +- app/src/main/res/menu/menu_settings.xml | 3 +- app/src/main/res/menu/menu_test.xml | 3 +- app/src/main/res/values-ru/strings.xml | 12 ++- app/src/main/res/values-uk/strings.xml | 21 ++++- app/src/main/res/values/dimens.xml | 1 + app/src/main/res/values/strings.xml | 12 ++- app/src/main/res/values/styles.xml | 2 + 34 files changed, 559 insertions(+), 111 deletions(-) create mode 100644 app/src/main/java/com/asoluter/litest/AnsverActivity.java delete mode 100644 app/src/main/java/com/asoluter/litest/Ansvers/AnsversDatabase.java create mode 100644 app/src/main/java/com/asoluter/litest/Objects/Pair.java create mode 100644 app/src/main/res/layout/activity_ansver.xml create mode 100644 app/src/main/res/layout/content_ansver.xml diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml index 8b6f4fb..4b69b52 100644 --- a/.idea/dbnavigator.xml +++ b/.idea/dbnavigator.xml @@ -2,7 +2,7 @@ - + diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d2e3f07..009a8d3 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -5,7 +5,7 @@ \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index 53aa26c..a03862f 100644 --- a/app/app.iml +++ b/app/app.iml @@ -65,39 +65,32 @@ - - - - + - - + + - - - - - - + + - - - + + + + - \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a56c2b4..eca2794 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ - + + android:screenOrientation="portrait" + android:theme="@style/AppTheme.Dark" > - @@ -33,6 +32,7 @@ android:name=".SignupActivity" android:label="@string/title_activity_signup" android:parentActivityName=".LoginActivity" + android:screenOrientation="portrait" android:theme="@style/AppTheme.Dark" > + android:label="@string/title_activity_test"> @@ -62,6 +61,13 @@ android:name="android.support.PARENT_ACTIVITY" android:value="com.asoluter.litest.MainActivity" /> + + + diff --git a/app/src/main/java/com/asoluter/litest/AnsverActivity.java b/app/src/main/java/com/asoluter/litest/AnsverActivity.java new file mode 100644 index 0000000..f1c2ccb --- /dev/null +++ b/app/src/main/java/com/asoluter/litest/AnsverActivity.java @@ -0,0 +1,35 @@ +package com.asoluter.litest; + +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.TextView; + +import com.asoluter.litest.Objects.Strings; + +public class AnsverActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_ansver); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + TextView ansText=(TextView)findViewById(R.id.ansText); + ansText.setText(getIntent().getStringExtra(Strings.TEST_RESULT)); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + // .setAction("Action", null).show(); + } + }); + } + +} diff --git a/app/src/main/java/com/asoluter/litest/Ansvers/AnsversDatabase.java b/app/src/main/java/com/asoluter/litest/Ansvers/AnsversDatabase.java deleted file mode 100644 index 51a9c63..0000000 --- a/app/src/main/java/com/asoluter/litest/Ansvers/AnsversDatabase.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.asoluter.litest.Ansvers; - -public class AnsversDatabase { - - - public void connectToDatabase(){ - - } -} diff --git a/app/src/main/java/com/asoluter/litest/ChooseTestActivity.java b/app/src/main/java/com/asoluter/litest/ChooseTestActivity.java index 898eb8d..7ebcddd 100644 --- a/app/src/main/java/com/asoluter/litest/ChooseTestActivity.java +++ b/app/src/main/java/com/asoluter/litest/ChooseTestActivity.java @@ -1,7 +1,11 @@ package com.asoluter.litest; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -12,29 +16,51 @@ import android.widget.ArrayAdapter; import android.widget.ListView; +import com.asoluter.litest.Objects.AnsObject; +import com.asoluter.litest.Objects.AuthObject; +import com.asoluter.litest.Objects.Pair; +import com.asoluter.litest.Objects.Strings; +import com.asoluter.litest.Objects.TypingObject; +import com.asoluter.litest.Services.Broadcasts.Broadcasts; +import com.asoluter.litest.Services.DBHelper.DBHelper; +import com.asoluter.litest.Services.ServerRequest; import com.asoluter.litest.Tests.TestsCover; +import java.util.ArrayList; + public class ChooseTestActivity extends AppCompatActivity { private Toolbar toolbar; private ListView chooseList; - Context context; + private Context contextt; private ArrayAdapter dataAdapter; + private int cont_pos; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_choose_test); - context=this; + contextt =this; initToolbar(); chooseList=(ListView)findViewById(R.id.choose_test_list); setTests(getIntent().getIntExtra( - getString(R.string.contest_pos) - ,0)); + getString(R.string.contest_pos),0)); + + BroadcastReceiver ansReceiver=new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + + Intent ansIntent=new Intent(contextt,AnsverActivity.class); + ansIntent.putExtra(Strings.TEST_RESULT,intent.getStringExtra(Strings.TEST_RESULT)); + startActivity(ansIntent); + } + }; + IntentFilter filter=new IntentFilter(Broadcasts.BROADCAST_ANSVER); + registerReceiver(ansReceiver,filter); } @Override @@ -52,9 +78,7 @@ public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } + return super.onOptionsItemSelected(item); } @@ -63,14 +87,15 @@ protected void setTests(int position){ dataAdapter=new ArrayAdapter(getApplicationContext(), R.layout.contest_list, TestsCover.getTests(position)); - + cont_pos=position; chooseList.setAdapter(dataAdapter); chooseList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - Intent testStart=new Intent(context,TestActivity.class); + Intent testStart=new Intent(contextt,TestActivity.class); testStart.putExtra(getString(R.string.test_pos), position); + testStart.putExtra(getString(R.string.contest_pos), cont_pos); testStart.putExtra(getString(R.string.quest), TestsCover.quests.get(position)); startActivity(testStart); @@ -78,22 +103,51 @@ public void onItemClick(AdapterView parent, View view, int position, long id) }); } + private static final String GET_ANSVERS="select cont_id,test_id,ans_id from ansvers where ((user=?)and(cont_id=?))"; + protected void initToolbar(){ toolbar=(Toolbar)findViewById(R.id.choose_test_toolbar); setSupportActionBar(toolbar); if(getSupportActionBar()!=null){ - getSupportActionBar().setTitle(R.string.app_name); + getSupportActionBar().setTitle(R.string.tests); + } toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { + switch (item.getItemId()){ + case R.id.action_send:{ + SQLiteDatabase database=new DBHelper(contextt).getReadableDatabase(); + + String login=getSharedPreferences("login",MODE_PRIVATE).getString("login", ""); + AuthObject auth_obj=new AuthObject(login,getSharedPreferences("login",MODE_PRIVATE).getString("pass","")); + + Cursor cursor=database.rawQuery(GET_ANSVERS, new String[]{login, String.valueOf(cont_pos)}); + cursor.moveToFirst(); + + ArrayList ansvers=new ArrayList<>(); + if (cursor.getCount()>0) + do{ + ansvers.add(new AnsObject(cursor.getInt(0),cursor.getInt(1),cursor.getInt(2))); + }while (cursor.moveToNext()); + + cursor.close(); + + TypingObject typingObject=new TypingObject(Strings.TEST,new Pair(auth_obj,ansvers)); + Intent intent=new Intent(contextt, ServerRequest.class); + intent.putExtra(Strings.COMMAND,typingObject); + startService(intent); + + break; + } + } return false; } }); - toolbar.inflateMenu(R.menu.menu_toolbar); + toolbar.inflateMenu(R.menu.menu_choose_test); } } diff --git a/app/src/main/java/com/asoluter/litest/LoginActivity.java b/app/src/main/java/com/asoluter/litest/LoginActivity.java index 7408c97..80cd1ca 100644 --- a/app/src/main/java/com/asoluter/litest/LoginActivity.java +++ b/app/src/main/java/com/asoluter/litest/LoginActivity.java @@ -68,6 +68,10 @@ protected void onCreate(Bundle savedInstanceState) { loginButton=(Button)findViewById(R.id.loginButton); signupButton=(Button)findViewById(R.id.signupButon); + + mail.setText(getSharedPreferences("login", MODE_PRIVATE).getString("login", "")); + pass.setText(getSharedPreferences("login",MODE_PRIVATE).getString("pass","")); + initToolbar(); cyclingAsync=new CyclingAsync(this); @@ -149,13 +153,12 @@ private void onLogin(){ saveCreds(); - - TypingObject context=new TypingObject(Strings.AUTH, new NullObject()); + TypingObject typingObject=new TypingObject(Strings.AUTH, new NullObject()); //cyclingAsync.execute(); service=new Intent(this,ServerRequest.class); - service.putExtra(Strings.COMMAND, context); + service.putExtra(Strings.COMMAND, typingObject); startService(service); } diff --git a/app/src/main/java/com/asoluter/litest/Objects/AnsObject.java b/app/src/main/java/com/asoluter/litest/Objects/AnsObject.java index 5f8b848..fee8fa8 100644 --- a/app/src/main/java/com/asoluter/litest/Objects/AnsObject.java +++ b/app/src/main/java/com/asoluter/litest/Objects/AnsObject.java @@ -3,6 +3,38 @@ import java.io.Serializable; public class AnsObject implements Serializable { - //TODO: Make object for answers + private int cont_id; + private int test_id; + private int ans_id; + public int getCont_id() { + return cont_id; + } + + public void setCont_id(int cont_id) { + this.cont_id = cont_id; + } + + public int getTest_id() { + return test_id; + } + + public void setTest_id(int test_id) { + this.test_id = test_id; + } + + public int getAns_id() { + return ans_id; + } + + public void setAns_id(int ans_id) { + this.ans_id = ans_id; + } + + public AnsObject(int cont_id, int test_id, int ans_id) { + this.cont_id = cont_id; + + this.test_id = test_id; + this.ans_id = ans_id; + } } diff --git a/app/src/main/java/com/asoluter/litest/Objects/Pair.java b/app/src/main/java/com/asoluter/litest/Objects/Pair.java new file mode 100644 index 0000000..310e116 --- /dev/null +++ b/app/src/main/java/com/asoluter/litest/Objects/Pair.java @@ -0,0 +1,29 @@ +package com.asoluter.litest.Objects; + +import java.io.Serializable; + +public class Pair implements Serializable { + private Object object; + private Object object1; + + public Pair(Object first, Object second) { + this.object = first; + this.object1 = second; + } + + public Object getSecond() { + return object1; + } + + public void setSecond(Object object1) { + this.object1 = object1; + } + + public Object getFirst() { + return object; + } + + public void setFirst(Object object) { + this.object = object; + } +} diff --git a/app/src/main/java/com/asoluter/litest/Objects/RegData.java b/app/src/main/java/com/asoluter/litest/Objects/RegData.java index 8c6dfe3..d058d09 100644 --- a/app/src/main/java/com/asoluter/litest/Objects/RegData.java +++ b/app/src/main/java/com/asoluter/litest/Objects/RegData.java @@ -1,34 +1,60 @@ package com.asoluter.litest.Objects; import java.io.Serializable; +import java.sql.Date; public class RegData implements Serializable { private String userName; + private String userLogin; private String userPassword; private String userMail; - private String userInfo; - - public RegData(String userName, String userPassword, String userMail, String userInfo) { + private Date userBirth; + public RegData(String userName, String userLogin, String userPassword, String userMail, Date userBirth) { this.userName = userName; + this.userLogin = userLogin; this.userPassword = userPassword; this.userMail = userMail; - this.userInfo = userInfo; + this.userBirth = userBirth; } public String getUserName() { return userName; } + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserLogin() { + return userLogin; + } + + public void setUserLogin(String userLogin) { + this.userLogin = userLogin; + } + public String getUserPassword() { return userPassword; } - public String getUserInfo() { - return userInfo; + public void setUserPassword(String userPassword) { + this.userPassword = userPassword; } public String getUserMail() { return userMail; } + + public void setUserMail(String userMail) { + this.userMail = userMail; + } + + public Date getUserBirth() { + return userBirth; + } + + public void setUserBirth(Date userBirth) { + this.userBirth = userBirth; + } } diff --git a/app/src/main/java/com/asoluter/litest/Objects/Strings.java b/app/src/main/java/com/asoluter/litest/Objects/Strings.java index 60da5bb..821d37a 100644 --- a/app/src/main/java/com/asoluter/litest/Objects/Strings.java +++ b/app/src/main/java/com/asoluter/litest/Objects/Strings.java @@ -10,6 +10,8 @@ public class Strings { public static final String AUTH="auth"; public static final String REGISTER="reg"; public static final String REFRESH="refresh"; + public static final String PAIR="pair"; + public static final String REG_RESULT="reg_result"; public static final String TEST="test"; public static final String TEST_RESULT="testRes"; diff --git a/app/src/main/java/com/asoluter/litest/Services/Broadcasts/Broadcasts.java b/app/src/main/java/com/asoluter/litest/Services/Broadcasts/Broadcasts.java index d95aa77..edbe572 100644 --- a/app/src/main/java/com/asoluter/litest/Services/Broadcasts/Broadcasts.java +++ b/app/src/main/java/com/asoluter/litest/Services/Broadcasts/Broadcasts.java @@ -6,6 +6,8 @@ public class Broadcasts { public static final String BROADCAST_LOGIN="login_service"; public static final String BROADCAST_REFRESH="refresh_service"; + public static final String BROADCAST_ANSVER="ansver_service"; + public static final String BROADCAST_REGISTER="reg_service"; public static final String BROADCAST_LOGIN_RESULT ="login_service_result"; public static final String BROADCAST_REFRESH_RESULT ="refresh_service_result"; diff --git a/app/src/main/java/com/asoluter/litest/Services/DBHelper/DBHelper.java b/app/src/main/java/com/asoluter/litest/Services/DBHelper/DBHelper.java index 6800c88..185558b 100644 --- a/app/src/main/java/com/asoluter/litest/Services/DBHelper/DBHelper.java +++ b/app/src/main/java/com/asoluter/litest/Services/DBHelper/DBHelper.java @@ -7,12 +7,13 @@ public class DBHelper extends SQLiteOpenHelper { public DBHelper(Context context){ - super(context,"myDb",null,1); + super(context,"testDb",null,1); } @Override public void onCreate(SQLiteDatabase db) { - db.execSQL("crea"); + db.execSQL("create table if not exists ansvers(user text ,cont_id int ," + + "test_id int, ans_id int, PRIMARY KEY(user,cont_id,test_id));"); } @Override diff --git a/app/src/main/java/com/asoluter/litest/Services/ServerRequest.java b/app/src/main/java/com/asoluter/litest/Services/ServerRequest.java index d523061..15137f0 100644 --- a/app/src/main/java/com/asoluter/litest/Services/ServerRequest.java +++ b/app/src/main/java/com/asoluter/litest/Services/ServerRequest.java @@ -9,11 +9,15 @@ import android.os.AsyncTask; import android.os.IBinder; +import com.asoluter.litest.Objects.AnsObject; import com.asoluter.litest.Objects.AuthObject; import com.asoluter.litest.Objects.DataBase; import com.asoluter.litest.Objects.NullObject; +import com.asoluter.litest.Objects.Pair; +import com.asoluter.litest.Objects.RegData; import com.asoluter.litest.Objects.Strings; import com.asoluter.litest.Objects.TypingObject; +import com.asoluter.litest.R; import com.asoluter.litest.Services.Broadcasts.Broadcasts; import com.asoluter.litest.Services.Broadcasts.Events.LoginResultEvent; import com.asoluter.litest.Services.Broadcasts.Events.RefreshResultEvent; @@ -25,6 +29,7 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; +import java.util.ArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -113,12 +118,26 @@ private void deBundle(){ break; } case Strings.TEST:{ - login(); + //if(login()){ + int result=sendAnsvers(); + + Intent intent=new Intent(Broadcasts.BROADCAST_ANSVER); + if(result==-1)intent.putExtra(Strings.TEST_RESULT,getString(R.string.invalid_result)); + else intent.putExtra(Strings.TEST_RESULT,String.valueOf(result)); + sendBroadcast(intent); + //} + break; + } + case Strings.REGISTER:{ + Intent intent=new Intent(Broadcasts.BROADCAST_REGISTER); + intent.putExtra(Broadcasts.RESULT,regResult()); + sendBroadcast(intent); break; } } } + private void runS(){ online=false; try { @@ -146,7 +165,7 @@ private void runS(){ } catch (IOException e) { e.printStackTrace(); } - } + }else stopSelf(); } @@ -159,7 +178,35 @@ private void stopS(){ } } + private int sendAnsvers(){ + if(online){ + try { + out.writeObject(typingObject); + TypingObject ret=(TypingObject)in.readObject(); + if(ret.getType().equals(Strings.TEST_RESULT)){ + return (int)ret.getObject(); + } + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + } + return -1; + } + + private int regResult(){ + if(online){ + try { + out.writeObject(typingObject); + TypingObject ret=(TypingObject)in.readObject(); + if(ret.getType().equals(Strings.OK))return 0; + } catch (IOException | ClassNotFoundException e) { + e.printStackTrace(); + } + + } + return -1; + } private boolean login(){ @@ -172,7 +219,10 @@ private boolean login(){ try { TypingObject ret=(TypingObject)in.readObject(); - if(ret.getType().equals(Strings.OK))return true; + if(ret.getType().equals(Strings.OK)){ + + return true; + } else if(ret.getType().equals(Strings.ERROR))return false; } catch (ClassNotFoundException e) { e.printStackTrace(); diff --git a/app/src/main/java/com/asoluter/litest/SettingsActivity.java b/app/src/main/java/com/asoluter/litest/SettingsActivity.java index 3fccae4..8c8246f 100644 --- a/app/src/main/java/com/asoluter/litest/SettingsActivity.java +++ b/app/src/main/java/com/asoluter/litest/SettingsActivity.java @@ -29,9 +29,7 @@ public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } + return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/com/asoluter/litest/SignupActivity.java b/app/src/main/java/com/asoluter/litest/SignupActivity.java index 4efcc4b..5a58350 100644 --- a/app/src/main/java/com/asoluter/litest/SignupActivity.java +++ b/app/src/main/java/com/asoluter/litest/SignupActivity.java @@ -1,16 +1,47 @@ package com.asoluter.litest; +import android.app.DatePickerDialog; +import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.support.design.widget.Snackbar; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.TextView; + +import com.asoluter.litest.Objects.RegData; +import com.asoluter.litest.Objects.Strings; +import com.asoluter.litest.Objects.TypingObject; +import com.asoluter.litest.Services.Broadcasts.Broadcasts; +import com.asoluter.litest.Services.ServerRequest; + +import java.sql.Date; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Locale; public class SignupActivity extends AppCompatActivity { Toolbar toolbar; + TextView nameText; + TextView loginText; + TextView passText; + TextView mailText; + TextView birthText; + + private SimpleDateFormat dateFormat; + private DatePickerDialog datePickerDialog; + private Date date; @Override protected void onCreate(Bundle savedInstanceState) { @@ -19,7 +50,60 @@ protected void onCreate(Bundle savedInstanceState) { initToolbar(); - /*TODO: MAKE SIGNUP */ + final Button signUpButton=(Button)findViewById(R.id.signupButon); + nameText=(TextView)findViewById(R.id.nameText); + loginText=(TextView)findViewById(R.id.loginText); + passText=(TextView)findViewById(R.id.passLoginText); + mailText=(TextView)findViewById(R.id.mailLoginText); + birthText=(TextView)findViewById(R.id.birthText); + + loginText.setText(getSharedPreferences("login", MODE_PRIVATE).getString("login", "")); + passText.setText(getSharedPreferences("login",MODE_PRIVATE).getString("pass","")); + + + Calendar calendar=Calendar.getInstance(); + dateFormat=new SimpleDateFormat("dd-MM-yyyy", Locale.US); + datePickerDialog=new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { + Calendar newDate=Calendar.getInstance(); + newDate.set(year, monthOfYear, dayOfMonth); + birthText.setText(dateFormat.format(newDate.getTime())); + date=new Date(newDate.getTime().getTime()); + } + },calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)); + + birthText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + datePickerDialog.show(); + } + }); + + BroadcastReceiver broadcastReceiver=new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if(intent.getIntExtra(Broadcasts.RESULT,-1)==0){ + Intent mainIntent=new Intent(SignupActivity.this,MainActivity.class); + mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(mainIntent); + }else Snackbar.make(signUpButton,getString(R.string.reg_not_ok),Snackbar.LENGTH_INDEFINITE).show(); + } + }; + IntentFilter filter=new IntentFilter(Broadcasts.BROADCAST_REGISTER); + registerReceiver(broadcastReceiver,filter); + + signUpButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TypingObject typingObject=new TypingObject(Strings.REGISTER,new RegData(nameText.getText().toString(), + loginText.getText().toString(),passText.getText().toString(), + mailText.getText().toString(),date)); + Intent service=new Intent(SignupActivity.this, ServerRequest.class); + service.putExtra(Strings.COMMAND,typingObject); + startService(service); + } + }); } protected void initToolbar(){ diff --git a/app/src/main/java/com/asoluter/litest/TestActivity.java b/app/src/main/java/com/asoluter/litest/TestActivity.java index e4969eb..8ebf7c9 100644 --- a/app/src/main/java/com/asoluter/litest/TestActivity.java +++ b/app/src/main/java/com/asoluter/litest/TestActivity.java @@ -1,6 +1,9 @@ package com.asoluter.litest; +import android.content.SharedPreferences; import android.content.res.Resources; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -14,6 +17,7 @@ import android.widget.TextView; import com.asoluter.litest.Objects.Strings; +import com.asoluter.litest.Services.DBHelper.DBHelper; import com.asoluter.litest.Tests.TestsCover; import java.util.ArrayList; @@ -25,6 +29,8 @@ public class TestActivity extends AppCompatActivity { private ArrayList radioButtons; private TextView questText; private LinearLayout chooseLayout; + private SQLiteDatabase database; + private SharedPreferences preferences; @Override protected void onCreate(Bundle savedInstanceState) { @@ -37,6 +43,10 @@ protected void onCreate(Bundle savedInstanceState) { setQuest(); setAnsvers(); + database=new DBHelper(this).getWritableDatabase(); + preferences=getSharedPreferences("login", MODE_PRIVATE); + + toggleChecked(); } @Override @@ -54,9 +64,6 @@ public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); //noinspection SimplifiableIfStatement - if (id == R.id.action_settings) { - return true; - } return super.onOptionsItemSelected(item); } @@ -116,6 +123,22 @@ private void setAnsvers(){ } + private void toggleChecked(){ + String toggledButton="select ans_id from ansvers where ((user=?)and(cont_id=?)and(test_id=?))"; + + int cont_id=getIntent().getIntExtra(getString(R.string.contest_pos), -1); + int test_id=getIntent().getIntExtra(getString(R.string.test_pos),-1); + Cursor cursor=database.rawQuery(toggledButton,new String[]{preferences.getString("login",""), + String.valueOf(cont_id),String.valueOf(test_id)}); + if(cursor.getCount()!=0){ + cursor.moveToFirst(); + int toggled=cursor.getInt(0); + toggleRadioButton(toggled); + } + + + } + private void toggleRadioButton(int n){ for (int i=0;i getContests(){ return Tests.getDataBase().getCont_name(); @@ -22,8 +23,8 @@ public static ArrayList getContests(){ public static ArrayList getTests(int contestPosition){ ArrayList tests=new ArrayList(); - test_id=new ArrayList(); - quests=new ArrayList(); + test_id=new ArrayList<>(); + quests=new ArrayList<>(); for(int i=0;i getTests(int contestPosition){ } public static Bundle getAnsvers(int testPosition){ - ArrayList ansvers=new ArrayList(); - ArrayList ans_id=new ArrayList(); + ArrayList ansvers=new ArrayList<>(); + ArrayList ans_id=new ArrayList<>(); for(int i=0;i + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_signup.xml b/app/src/main/res/layout/activity_signup.xml index 064701e..dc37486 100644 --- a/app/src/main/res/layout/activity_signup.xml +++ b/app/src/main/res/layout/activity_signup.xml @@ -88,10 +88,12 @@ android:layout_width="280dp" android:layout_height="wrap_content" android:hint="@string/birth_label" - android:inputType="date" android:ems="10" android:id="@+id/birthText" - android:layout_marginBottom="4dp" /> + android:layout_marginBottom="4dp" + android:focusable="false" + android:editable="true" + android:clickable="true" />