commit 5336bbc109d026723349dcea0bafebdddc7d9143 Author: Yohann D'ANELLO Date: Mon Dec 2 11:55:23 2019 +0100 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..52ac49a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Tarot ENS \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..d291b3d --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d5fe702 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "fr.ynerant.tarot" + minSdkVersion 24 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.navigation:navigation-fragment:2.1.0' + implementation 'androidx.navigation:navigation-ui:2.1.0' + implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation 'com.google.code.gson:gson:2.8.6' + implementation 'commons-io:commons-io:2.6' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/fr/ynerant/tarot/ExampleInstrumentedTest.java b/app/src/androidTest/java/fr/ynerant/tarot/ExampleInstrumentedTest.java new file mode 100644 index 0000000..23272c9 --- /dev/null +++ b/app/src/androidTest/java/fr/ynerant/tarot/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package fr.ynerant.tarot; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("fr.ynerant.tarot", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5c62b2e --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/fr/ynerant/tarot/Game.java b/app/src/main/java/fr/ynerant/tarot/Game.java new file mode 100644 index 0000000..a38bf28 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/Game.java @@ -0,0 +1,185 @@ +package fr.ynerant.tarot; + +import android.preference.PreferenceManager; +import android.util.SparseArray; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Executors; + +public class Game { + private static final SparseArray GAMES = new SparseArray<>(); + + public int id; + public GameType type; + public Set players; + public Bet bet; + public Player attacker; + public Player follower; + public int attackScore; +// public boolean little, twenty_one, excuse; + public int ends; + public int handle; + public Map miseries; + public boolean littleForAttacker, littleForDefenser; + public boolean chelemAnnounced, chelemRealized; + + public int getId() { + return id; + } + + public GameType getType() { + return type; + } + + public Set getPlayers() { + return players; + } + + public Bet getBet() { + return bet; + } + + public Player getAttacker() { + return attacker; + } + + public Player getFollower() { + return follower; + } + + public int getAttackScore() { + return attackScore; + } + + public int getEnds() { + return ends; + } + + public int getHandle() { + return handle; + } + + public Map getMiseries() { + return miseries; + } + + public boolean isLittleForAttacker() { + return littleForAttacker; + } + + public boolean isLittleForDefenser() { + return littleForDefenser; + } + + public boolean isChelemAnnounced() { + return chelemAnnounced; + } + + public boolean isChelemRealized() { + return chelemRealized; + } + + public int calculateScore() { + // int ends = (little ? 1 : 0) + (twenty_one ? 1 : 0) + (excuse ? 1 : 0); + int bound = ends == 0 ? 56 : ends == 1 ? 51 : ends == 2 ? 41 : 36; + boolean win = attackScore >= bound; + int gain = Math.abs(attackScore - bound); + int score = 25; + score += gain; + + score *= bet.getMultiplier(); + + if (handle != 0) + score += 10 * (Math.abs(handle) + 1); + + if (!win) + score = -score; + + if (littleForAttacker) + score += 10; + else if (littleForDefenser) + score -= 10; + + if (chelemAnnounced) { + if (chelemRealized) + score += 400; + else + score -= 200; + } + else if (chelemRealized) + score += 200; + + return score; + } + + public enum GameType { + THREE_PLAYERS, FOUR_PLAYERS, FIVE_PLAYERS, SIX_PLAYERS; + + public int getNbPlayers() { + return ordinal() + 3; + } + + public static GameType getGameType(int players) { + switch (players) { + case 3: + return THREE_PLAYERS; + case 4: + return FOUR_PLAYERS; + case 5: + return FIVE_PLAYERS; + case 6: + return SIX_PLAYERS; + default: + throw new IllegalArgumentException("A game must have between 3 and 6 players"); + } + } + } + + public enum Bet { + SMALL(1), GUARD(2), GUARD_WITHOUT(4), GUARD_AGAINST(6); + + private final int multiplier; + + Bet(int multiplier) { + this.multiplier = multiplier; + } + + public int getMultiplier() { + return multiplier; + } + } + + public static void updateGames() { + Executors.newSingleThreadExecutor().execute(new Runnable() { + @Override + public void run() { + try { + URL url = new URL("http://galaxyoyo.com/tarot/game.php"); + final HttpURLConnection co = (HttpURLConnection) url.openConnection(); + co.setRequestMethod("POST"); + co.setRequestProperty("token", PreferenceManager.getDefaultSharedPreferences(MainActivity.INSTANCE).getString("token", null)); + co.connect(); + + final List games = new Gson().fromJson(new InputStreamReader(co.getInputStream()), new TypeToken>(){}.getType()); + GAMES.clear(); + for (Game g : games) { + GAMES.put(g.getId(), g); + } + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + }); + } +} diff --git a/app/src/main/java/fr/ynerant/tarot/MainActivity.java b/app/src/main/java/fr/ynerant/tarot/MainActivity.java new file mode 100644 index 0000000..be9c360 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/MainActivity.java @@ -0,0 +1,62 @@ +package fr.ynerant.tarot; + +import android.content.Context; +import android.os.Bundle; + +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.navigation.ui.AppBarConfiguration; +import androidx.navigation.ui.NavigationUI; + +import com.google.android.material.navigation.NavigationView; + +import androidx.drawerlayout.widget.DrawerLayout; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import android.view.Menu; + +public class MainActivity extends AppCompatActivity { + + public static MainActivity INSTANCE; + private AppBarConfiguration mAppBarConfiguration; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + INSTANCE = this; + + Player.updatePlayers(); + Game.updateGames(); + + setContentView(R.layout.activity_main); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + DrawerLayout drawer = findViewById(R.id.drawer_layout); + NavigationView navigationView = findViewById(R.id.nav_view); + // Passing each menu ID as a set of Ids because each + // menu should be considered as top level destinations. + mAppBarConfiguration = new AppBarConfiguration.Builder( + R.id.nav_new_game) + .setDrawerLayout(drawer) + .build(); + NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); + NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration); + NavigationUI.setupWithNavController(navigationView, navController); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + + @Override + public boolean onSupportNavigateUp() { + NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); + return NavigationUI.navigateUp(navController, mAppBarConfiguration) + || super.onSupportNavigateUp(); + } +} diff --git a/app/src/main/java/fr/ynerant/tarot/Player.java b/app/src/main/java/fr/ynerant/tarot/Player.java new file mode 100644 index 0000000..b9d1cb5 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/Player.java @@ -0,0 +1,105 @@ +package fr.ynerant.tarot; + +import android.annotation.SuppressLint; +import android.preference.PreferenceManager; +import android.widget.Toast; + +import androidx.annotation.NonNull; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executors; + +public class Player { + @SuppressLint("UseSparseArrays") + private static final Map PLAYERS = new HashMap<>(); + public static Player THIS_PLAYER; + + private int id; + + private String name; + + private int score3, score4, score5, score6; + + private int getId() { + return id; + } + + public String getName() { + return name; + } + + public int getScore3() { + return score3; + } + + public int getScore4() { + return score4; + } + + public int getScore5() { + return score5; + } + + public int getScore6() { + return score6; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof Player && ((Player) obj).getId() == getId(); + } + + public static void updatePlayers() { + Executors.newSingleThreadExecutor().execute(new Runnable() { + @Override + public void run() { + try { + URL url = new URL("http://galaxyoyo.com/tarot/player.php"); + final HttpURLConnection co = (HttpURLConnection) url.openConnection(); + co.setRequestMethod("POST"); + co.setRequestProperty("token", PreferenceManager.getDefaultSharedPreferences(MainActivity.INSTANCE).getString("token", null)); + co.connect(); + + final List players = new Gson().fromJson(new InputStreamReader(co.getInputStream()), new TypeToken>(){}.getType()); + PLAYERS.clear(); + for (Player p : players) { + PLAYERS.put(p.getId(), p); + } + + THIS_PLAYER = PLAYERS.get(PreferenceManager.getDefaultSharedPreferences(MainActivity.INSTANCE).getInt("user_id", 0)); + + MainActivity.INSTANCE.runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(MainActivity.INSTANCE, "Bienvenue " + THIS_PLAYER.getName() + " !", Toast.LENGTH_SHORT).show(); + } + }); + } + catch (IOException ex) { + ex.printStackTrace(); + } + } + }); + } + + public static Collection getAllPlayers() { + return PLAYERS.values(); + } + + @NonNull + @Override + public String toString() { + return name; + } +} diff --git a/app/src/main/java/fr/ynerant/tarot/ui/home/HomeFragment.java b/app/src/main/java/fr/ynerant/tarot/ui/home/HomeFragment.java new file mode 100644 index 0000000..3a16893 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/ui/home/HomeFragment.java @@ -0,0 +1,106 @@ +package fr.ynerant.tarot.ui.home; + +import android.os.Bundle; +import android.os.Looper; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProviders; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.concurrent.Executors; + +import fr.ynerant.tarot.Game; +import fr.ynerant.tarot.MainActivity; +import fr.ynerant.tarot.Player; +import fr.ynerant.tarot.R; +import fr.ynerant.tarot.ui.newgame.NewGameFragment; + +public class HomeFragment extends Fragment { + + private HomeViewModel homeViewModel; + + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + homeViewModel = + ViewModelProviders.of(this).get(HomeViewModel.class); + final View root = inflater.inflate(R.layout.fragment_home, container, false); + + if (PreferenceManager.getDefaultSharedPreferences(MainActivity.INSTANCE).getString("token", null) != null) { + //noinspection ConstantConditions + getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new NewGameFragment(), "Nouvelle partie").commit(); + return root; + } + + TextView textView = root.findViewById(R.id.text_home); + textView.setText(R.string.welcome); + + Button login = root.findViewById(R.id.login); + login.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final EditText token = root.findViewById(R.id.token); + + Executors.newSingleThreadExecutor().execute(new Runnable() { + @Override + public void run() { + try { + Looper.prepare(); + URL url = new URL("http://galaxyoyo.com/tarot/check_token.php"); + final HttpURLConnection co = (HttpURLConnection) url.openConnection(); + co.setRequestMethod("POST"); + co.setRequestProperty("token", token.getText().toString()); + co.connect(); + final int resp = co.getResponseCode(); + + MainActivity.INSTANCE.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + if (resp == 403) + Toast.makeText(root.getContext(), "Utilisateur non trouvé", Toast.LENGTH_LONG).show(); + else { + String content = IOUtils.readLines(co.getInputStream(), StandardCharsets.UTF_8).get(0); + HashMap map = new Gson().fromJson(content, new TypeToken>(){}.getType()); + //noinspection ConstantConditions + int id = map.getOrDefault("id", 0); + PreferenceManager.getDefaultSharedPreferences(root.getContext()).edit().putString("token", token.getText().toString()).putInt("user_id", id).apply(); + Player.updatePlayers(); + Game.updateGames(); + //noinspection ConstantConditions + getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new NewGameFragment(), "Nouvelle partie").commit(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + }); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + + } + }); + + return root; + } +} \ No newline at end of file diff --git a/app/src/main/java/fr/ynerant/tarot/ui/home/HomeViewModel.java b/app/src/main/java/fr/ynerant/tarot/ui/home/HomeViewModel.java new file mode 100644 index 0000000..ecb0388 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/ui/home/HomeViewModel.java @@ -0,0 +1,9 @@ +package fr.ynerant.tarot.ui.home; + +import androidx.lifecycle.ViewModel; + +public class HomeViewModel extends ViewModel { + + public HomeViewModel() { + } +} \ No newline at end of file diff --git a/app/src/main/java/fr/ynerant/tarot/ui/newgame/NewGameFragment.java b/app/src/main/java/fr/ynerant/tarot/ui/newgame/NewGameFragment.java new file mode 100644 index 0000000..0dd6963 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/ui/newgame/NewGameFragment.java @@ -0,0 +1,323 @@ +package fr.ynerant.tarot.ui.newgame; + +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.Spinner; +import android.widget.SpinnerAdapter; +import android.widget.Switch; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProviders; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Locale; + +import fr.ynerant.tarot.Game; +import fr.ynerant.tarot.MainActivity; +import fr.ynerant.tarot.Player; +import fr.ynerant.tarot.R; +import fr.ynerant.tarot.ui.home.HomeFragment; + +public class NewGameFragment extends Fragment { + + private NewGameViewModel newGameViewModel; + + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + newGameViewModel = + ViewModelProviders.of(this).get(NewGameViewModel.class); + final View root = inflater.inflate(R.layout.fragment_new_game, container, false); + + if (PreferenceManager.getDefaultSharedPreferences(MainActivity.INSTANCE).getString("token", null) == null) { + //noinspection ConstantConditions + getFragmentManager().beginTransaction().replace(R.id.nav_host_fragment, new HomeFragment(), "Se connecter").commit(); + return root; + } + + TextView textView = root.findViewById(R.id.text_new_game); + textView.setText(R.string.menu_new_game); + + final SeekBar nb_players = root.findViewById(R.id.nb_players); + final Spinner player1 = root.findViewById(R.id.player1); + final Spinner player2 = root.findViewById(R.id.player2); + final Spinner player3 = root.findViewById(R.id.player3); + final Spinner player4 = root.findViewById(R.id.player4); + final Spinner player5 = root.findViewById(R.id.player5); + final Spinner player6 = root.findViewById(R.id.player6); + final LinearLayout player4_layout = root.findViewById(R.id.player4_layout); + final LinearLayout player5_layout = root.findViewById(R.id.player5_layout); + final LinearLayout player6_layout = root.findViewById(R.id.player6_layout); + + //noinspection ConstantConditions + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, new ArrayList<>(Player.getAllPlayers())); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + player1.setAdapter(adapter); + player2.setAdapter(adapter); + player3.setAdapter(adapter); + player4.setAdapter(adapter); + player5.setAdapter(adapter); + player6.setAdapter(adapter); + final Spinner[] spinners = new Spinner[]{player1, player2, player3, player4, player5, player6}; + + final SeekBar attack_points = root.findViewById(R.id.attack_score); + final SeekBar bet = root.findViewById(R.id.bet); + final SeekBar nb_ends = root.findViewById(R.id.nb_ends); + final Switch chelem_announced = root.findViewById(R.id.chelem_announced); + final Switch chelem_realized = root.findViewById(R.id.chelem_realized); + final SeekBar little_end = root.findViewById(R.id.little_end); + final SeekBar handle = root.findViewById(R.id.handle); + + final Runnable updateScore = new Runnable() { + @Override + public void run() { + TextView textView = root.findViewById(R.id.nb_points); + Game game = new Game(); + game.attackScore = attack_points.getProgress(); + game.type = Game.GameType.getGameType(nb_players.getProgress() + 3); + game.players = new HashSet<>(); + for (int i = 0; i < 3 + nb_players.getProgress(); ++i) { + game.players.add((Player) spinners[i].getSelectedItem()); + } + game.bet = Game.Bet.values()[bet.getProgress()]; + game.ends = nb_ends.getProgress(); + game.chelemAnnounced = chelem_announced.isChecked(); + game.chelemRealized = chelem_realized.isChecked(); + game.littleForAttacker = little_end.getProgress() == 1; + game.littleForDefenser = little_end.getProgress() == 2; + game.handle = handle.getProgress(); + + + textView.setText(String.format(Locale.getDefault(), "%d points (hors misères)", game.calculateScore())); + } + }; + + updateScore.run(); + + nb_players.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + TextView nb_players_info = root.findViewById(R.id.nb_players_info); + int resource = R.string.players4; + switch (progress) { + case 0: + resource = R.string.players3; + break; + case 1: + resource = R.string.players4; + break; + case 2: + resource = R.string.players5; + break; + case 3: + resource = R.string.players6; + break; + } + nb_players_info.setText(resource); + + player4_layout.setVisibility(View.GONE); + player5_layout.setVisibility(View.GONE); + player6_layout.setVisibility(View.GONE); + + switch (progress + 3) { + case 6: + player6_layout.setVisibility(View.VISIBLE); + case 5: + player5_layout.setVisibility(View.VISIBLE); + case 4: + player4_layout.setVisibility(View.VISIBLE); + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + + @Override + public void onStopTrackingTouch(SeekBar seekBar) {} + }); + + attack_points.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + TextView attack = root.findViewById(R.id.nb_points_attack); + TextView defense = root.findViewById(R.id.nb_points_defense); + attack.setText(String.valueOf(progress)); + defense.setText(String.valueOf(91 - progress)); + + updateScore.run(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + + @Override + public void onStopTrackingTouch(SeekBar seekBar) {} + }); + + bet.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + TextView textView = root.findViewById(R.id.bet_info); + switch (progress) { + case 1: + textView.setText(R.string.guard); + break; + case 2: + textView.setText(R.string.guard_without); + break; + case 3: + textView.setText(R.string.guard_against); + break; + default: + textView.setText(R.string.little); + break; + } + + updateScore.run(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + + nb_ends.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + TextView textView = root.findViewById(R.id.nb_ends_info); + switch (progress) { + case 1: + textView.setText(R.string.one_end); + break; + case 2: + textView.setText(R.string.two_ends); + break; + case 3: + textView.setText(R.string.three_ends); + break; + default: + textView.setText(R.string.null_end); + break; + } + + updateScore.run(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + + chelem_announced.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + updateScore.run(); + } + }); + + chelem_realized.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + updateScore.run(); + } + }); + + little_end.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + TextView textView = root.findViewById(R.id.little_end_info); + switch (progress) { + case 1: + textView.setText(R.string.for_attacker); + break; + case 2: + textView.setText(R.string.for_defenser); + break; + default: + textView.setText(R.string.no); + break; + } + + updateScore.run(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + + attack_points.setProgress(46); + + handle.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + TextView textView = root.findViewById(R.id.handle_info); + switch (progress) { + case -3: + textView.setText(R.string.handle_3d); + break; + case -2: + textView.setText(R.string.handle_2d); + break; + case -1: + textView.setText(R.string.handle_1d); + break; + case 1: + textView.setText(R.string.handle_1a); + break; + case 2: + textView.setText(R.string.handle_2a); + break; + case 3: + textView.setText(R.string.handle_3a); + break; + default: + textView.setText(R.string.no_handle); + break; + } + + updateScore.run(); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + + final Button btn = root.findViewById(R.id.add_game_button); + btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(getContext(), "La partie sera sauvegardée ultérieurement.", Toast.LENGTH_SHORT).show(); + } + }); + + return root; + } +} \ No newline at end of file diff --git a/app/src/main/java/fr/ynerant/tarot/ui/newgame/NewGameViewModel.java b/app/src/main/java/fr/ynerant/tarot/ui/newgame/NewGameViewModel.java new file mode 100644 index 0000000..b55aba6 --- /dev/null +++ b/app/src/main/java/fr/ynerant/tarot/ui/newgame/NewGameViewModel.java @@ -0,0 +1,9 @@ +package fr.ynerant.tarot.ui.newgame; + +import androidx.lifecycle.ViewModel; + +public class NewGameViewModel extends ViewModel { + + public NewGameViewModel() { + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_menu_camera.xml b/app/src/main/res/drawable/ic_menu_camera.xml new file mode 100644 index 0000000..634fe92 --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_camera.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_menu_gallery.xml b/app/src/main/res/drawable/ic_menu_gallery.xml new file mode 100644 index 0000000..03c7709 --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_gallery.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_menu_manage.xml b/app/src/main/res/drawable/ic_menu_manage.xml new file mode 100644 index 0000000..aeb047d --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_manage.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_menu_send.xml b/app/src/main/res/drawable/ic_menu_send.xml new file mode 100644 index 0000000..fdf1c90 --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_send.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_menu_share.xml b/app/src/main/res/drawable/ic_menu_share.xml new file mode 100644 index 0000000..338d95a --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_share.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_menu_slideshow.xml b/app/src/main/res/drawable/ic_menu_slideshow.xml new file mode 100644 index 0000000..5e9e163 --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_slideshow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/side_nav_bar.xml b/app/src/main/res/drawable/side_nav_bar.xml new file mode 100644 index 0000000..6d81870 --- /dev/null +++ b/app/src/main/res/drawable/side_nav_bar.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..8e69e22 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml new file mode 100644 index 0000000..9c96440 --- /dev/null +++ b/app/src/main/res/layout/app_bar_main.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..04b67fd --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml new file mode 100644 index 0000000..a33cc12 --- /dev/null +++ b/app/src/main/res/layout/fragment_home.xml @@ -0,0 +1,25 @@ + + + + + + + +