Skip to content

Commit

Permalink
✨ Made a fake login and register on local database
Browse files Browse the repository at this point in the history
Support fake login and register on local database and remove useless file
  • Loading branch information
HUSTERGS committed Oct 21, 2019
1 parent 37ce7ad commit c8b1244
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 173 deletions.
11 changes: 7 additions & 4 deletions SudokuApp-GS/Sudoku/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".History" />
<activity android:name=".ChooseType" />
<activity android:name=".ChooseLevel" />
<activity android:name=".SudokuNine" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Expand Down
3 changes: 2 additions & 1 deletion SudokuApp-GS/Sudoku/app/src/main/assets/litepal.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<litepal>
<dbname value="GameHistory"></dbname>
<version value="2"></version>
<version value="3"></version>
<list>
<mapping class="com.example.sudoku.LastRecord"></mapping>
<mapping class="com.example.sudoku.GameRecord"></mapping>
<mapping class="com.example.sudoku.userInfo"></mapping>
</list>
</litepal>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

Expand Down Expand Up @@ -30,11 +31,14 @@ public void onClick(View v) {
Intent intent = new Intent(ChooseType.this, ChooseLevel.class);
intent.putExtra("gridLength", 4);

List<LastRecord> records = LitePal.findAll(LastRecord.class);
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

List<LastRecord> records = LitePal.where("user = ?", name).find(LastRecord.class);
if (!records.isEmpty()) {
LastRecord preRecord = records.get(0);
LastRecord.LastToHistory(preRecord).save();
LitePal.deleteAll(LastRecord.class);
LitePal.deleteAll(LastRecord.class, "user = ?", name);
}
startActivity(intent);
}
Expand All @@ -45,19 +49,25 @@ public void onClick(View v) {
public void onClick(View v) {
Intent intent = new Intent(ChooseType.this, ChooseLevel.class);
intent.putExtra("gridLength", 9);
List<LastRecord> records = LitePal.findAll(LastRecord.class);
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

List<LastRecord> records = LitePal.where("user = ?", name).find(LastRecord.class);
if (!records.isEmpty()) {
LastRecord preRecord = records.get(0);
LastRecord.LastToHistory(preRecord).save();
LitePal.deleteAll(LastRecord.class);
LitePal.deleteAll(LastRecord.class, "user = ?", name);
}
startActivity(intent);
}
});

MaterialButton resume = (MaterialButton) findViewById(R.id.resume);

List<LastRecord> record = LitePal.findAll(LastRecord.class);
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

List<LastRecord> record = LitePal.where("user = ?", name).find(LastRecord.class);
if (record.isEmpty()) {
// resume.setClickable(false);
resume.setVisibility(View.GONE);
Expand All @@ -66,9 +76,12 @@ public void onClick(View v) {
resume.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

Intent intent = new Intent(ChooseType.this, SudokuNine.class);
intent.putExtra("resume", true);
intent.putExtra("gridLength", LitePal.findAll(LastRecord.class).get(0).getType());
intent.putExtra("gridLength", LitePal.where("user = ?", name).find(LastRecord.class).get(0).getType());
startActivity(intent);
}
});
Expand All @@ -78,8 +91,10 @@ public void onClick(View v) {
protected void onResume() {
super.onResume();
MaterialButton resume = (MaterialButton) findViewById(R.id.resume);
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

List<LastRecord> record = LitePal.findAll(LastRecord.class);
List<LastRecord> record = LitePal.where("user = ?", name).find(LastRecord.class);
if (!record.isEmpty()) {
// resume.setClickable(false);
resume.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.SharedPreferences;
import android.os.Bundle;

import org.litepal.LitePal;
Expand All @@ -27,8 +28,11 @@ protected void onCreate(Bundle savedInstanceState) {

layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
// LitePal.findAll(GameRecord.class);
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

List<GameRecord> gameRecords = LitePal.findAll(GameRecord.class);
List<GameRecord> gameRecords = LitePal.where("user = ?", name).find(GameRecord.class);
Collections.reverse(gameRecords);
mAdapter = new HistoryItemAdapter(gameRecords);
recyclerView.setAdapter(mAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
GameRecord gameRecord= mHistory.get(position);
holder.userText.setText(gameRecord.getUser());
holder.timeText.setText(formatInterval(-gameRecord.getusedTime()));
holder.typeText.setText(Integer.toString(gameRecord.getType()));
holder.typeText.setText(gameRecord.getType() == 9 ? "九宫" : "四宫");
int level = gameRecord.getLevel();
String[] texts = new String[] {"简单", "中等", "困难", "极难"};
if (gameRecord.getType() == 9) {
Expand Down
41 changes: 41 additions & 0 deletions SudokuApp-GS/Sudoku/app/src/main/java/com/example/sudoku/MD5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.sudoku;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {
public static String getMd5(String input)
{
try {

// Static getInstance method is called with hashing MD5
MessageDigest md = MessageDigest.getInstance("MD5");

// digest() method is called to calculate message digest
// of an input digest() return array of byte
byte[] messageDigest = md.digest(input.getBytes());

// Convert byte array into signum representation
BigInteger no = new BigInteger(1, messageDigest);

// Convert message digest into hex value
String hashtext = no.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
}

// For specifying wrong message digest algorithms
catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

// Driver code
public static void main(String args[]) throws NoSuchAlgorithmException
{
String s = "GeeksForGeeks";
System.out.println("Your HashCode Generated by MD5 is: " + getMd5(s));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.material.button.MaterialButton;

Expand All @@ -17,9 +19,9 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LitePal.initialize(this);
// LitePal.initialize(this);
setContentView(R.layout.activity_main);
LitePal.getDatabase();
// LitePal.getDatabase();
MaterialButton startGame = findViewById(R.id.materialButton4);
startGame.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -38,5 +40,12 @@ public void onClick(View v) {
}
});

SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");
if (name == "Anonymous") {
Toast.makeText(getApplicationContext(), "你以匿名模式登录" + name, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "欢迎来到数独世界~ " + name, Toast.LENGTH_SHORT).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.location.GnssMeasurementsEvent;
Expand Down Expand Up @@ -167,7 +168,10 @@ private void enterHistoryNote() {
}
// 恢复上一次的数据
private void resumeLastRecord() {
List<LastRecord> records = LitePal.findAll(LastRecord.class);
SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");

List<LastRecord> records = LitePal.where("user = ?", name).find(LastRecord.class);
LastRecord lastRecord = records.get(0);

// 初始棋局
Expand Down Expand Up @@ -640,7 +644,10 @@ protected void onUserLeaveHint(){
ImageButton pause = findViewById(R.id.pause);
pause.callOnClick();

LitePal.deleteAll(LastRecord.class);

SharedPreferences pref = getSharedPreferences("currentUser", MODE_PRIVATE);
String name = pref.getString("name", "");
LitePal.deleteAll(LastRecord.class, "user = ?", name);

LastRecord lastRecord = new LastRecord();
lastRecord.setAnwser(GenerateBoard.boardToString(anwserBoard));
Expand All @@ -651,7 +658,9 @@ protected void onUserLeaveHint(){
lastRecord.setShowColor(showColor ? 1 : 0);
lastRecord.setusedTime(timeWhenStopped);
lastRecord.setshowHint(showHint ? 1 : 0);
lastRecord.setUser("anonymous,");


lastRecord.setUser(name);
lastRecord.setType(S);
lastRecord.save();
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit c8b1244

Please sign in to comment.