Skip to content

Commit

Permalink
Donations links and main menu done
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanloy committed Feb 10, 2019
1 parent 93aeb42 commit 3c192c0
Show file tree
Hide file tree
Showing 34 changed files with 251 additions and 34 deletions.
2 changes: 1 addition & 1 deletion MentalBlocks2/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionName "v0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file added MentalBlocks2/app/release/release/app.aab
Binary file not shown.
10 changes: 8 additions & 2 deletions MentalBlocks2/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".LevelActivity" android:screenOrientation="portrait">
<activity
android:name=".LevelActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name=".LevelListActivity" android:screenOrientation="portrait">
<activity
android:name=".LevelListActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name=".MainMenuActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Binary file added MentalBlocks2/app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package com.ivanloy.mentalblocks

import android.app.Activity
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.Adapter
import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.android.synthetic.main.activity_level_list.*
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_level.*
import java.lang.StringBuilder


class LevelListActivity : AppCompatActivity(), LevelListListener {
class LevelListActivity : AppCompatActivity(), LevelListListener, View.OnClickListener {

private var levels = ArrayList<Level>()
private var adapter : LevelAdapter? = null


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
Expand All @@ -27,23 +32,26 @@ class LevelListActivity : AppCompatActivity(), LevelListListener {
setContentView(R.layout.activity_level)
setContentView(R.layout.activity_level_list)


tv_puzzlesSolved.text = TextUtil.fromHtml("<b><big>0</big></b> / <small>12</small>")
btn_goBackToMain.setOnClickListener(this)

levels = ArrayList<Level>()

levels.add(Level(1, LevelsData.LEVEL_1.data, getDrawable(R.drawable.level1), true))
levels.add(Level(2, LevelsData.LEVEL_2.data, getDrawable(R.drawable.level2), true))
levels.add(Level(3, LevelsData.LEVEL_3.data, getDrawable(R.drawable.level3), true))
levels.add(Level(4, LevelsData.LEVEL_4.data, getDrawable(R.drawable.level4), true))
levels.add(Level(5, LevelsData.LEVEL_5.data, getDrawable(R.drawable.level5), true))
levels.add(Level(6, LevelsData.LEVEL_6.data, getDrawable(R.drawable.level6), true))
levels.add(Level(7, LevelsData.LEVEL_7.data, getDrawable(R.drawable.level7), true))
levels.add(Level(8, LevelsData.LEVEL_8.data, getDrawable(R.drawable.level8), true))
levels.add(Level(9, LevelsData.LEVEL_9.data, getDrawable(R.drawable.level9), true))
levels.add(Level(10, LevelsData.LEVEL_10.data, getDrawable(R.drawable.level10), true))
levels.add(Level(11, LevelsData.LEVEL_11.data, getDrawable(R.drawable.level11), true))
levels.add(Level(12, LevelsData.LEVEL_12.data, getDrawable(R.drawable.level12), true))
levels.add(Level(2, LevelsData.LEVEL_2.data, getDrawable(R.drawable.level2), false))
levels.add(Level(3, LevelsData.LEVEL_3.data, getDrawable(R.drawable.level3), false))
levels.add(Level(4, LevelsData.LEVEL_4.data, getDrawable(R.drawable.level4), false))
levels.add(Level(5, LevelsData.LEVEL_5.data, getDrawable(R.drawable.level5), false))
levels.add(Level(6, LevelsData.LEVEL_6.data, getDrawable(R.drawable.level6), false))
levels.add(Level(7, LevelsData.LEVEL_7.data, getDrawable(R.drawable.level7), false))
levels.add(Level(8, LevelsData.LEVEL_8.data, getDrawable(R.drawable.level8), false))
levels.add(Level(9, LevelsData.LEVEL_9.data, getDrawable(R.drawable.level9), false))
levels.add(Level(10, LevelsData.LEVEL_10.data, getDrawable(R.drawable.level10), false))
levels.add(Level(11, LevelsData.LEVEL_11.data, getDrawable(R.drawable.level11), false))
levels.add(Level(12, LevelsData.LEVEL_12.data, getDrawable(R.drawable.level12), false))

loadData()

tv_puzzlesSolved.text = TextUtil.fromHtml("<b><big>${getNLevelsSolved()}</big></b> / <small>12</small>")

rv_levelList.layoutManager = GridLayoutManager(
this,
Expand Down Expand Up @@ -73,16 +81,29 @@ class LevelListActivity : AppCompatActivity(), LevelListListener {
var nLevel = data!!.getIntExtra("nLevelResponse", 0) - 1
levels[nLevel].completed = true
tv_puzzlesSolved.text = TextUtil.fromHtml("<b><big>${getNLevelsSolved()}</big></b> / <small>12</small>")
if(nLevel < 12) { //TODO Hardcoded
if(nLevel < 11) { //TODO Hardcoded
levels[nLevel + 1].unlocked = true
}

saveData()
adapter!!.setData(levels)
}
}
}
}

override fun onClick(v: View?) {
when(v!!.id){
R.id.btn_goBackToMain -> {
finish()
}
}
}

override fun onDestroy() {
Log.d("Patata", "onDestroy")
super.onDestroy()
}

fun getNLevelsSolved() : Int{
var ret = 0
for(lev in levels){
Expand All @@ -91,4 +112,30 @@ class LevelListActivity : AppCompatActivity(), LevelListListener {
return ret
}

fun saveData() {
var data = StringBuilder()
Log.d("Patata", "saveData")
for(level in levels){
data.append("${level.unlocked},${level.completed} ")
}
Log.d("Patata", data.toString())
SerializableManager.saveSerializable(this, data.toString(), "levelData.sav")
}

fun loadData(){
var data = SerializableManager
.readSerializable<String>(this, "levelData.sav")

if(data != null) {
var parsedData = data.split(" ")
if (parsedData.size > 0) {
for (i in 0..11) { //TODO Hardcoded
var line = parsedData[i].split(",")
levels[i].unlocked = line[0].toBoolean()
levels[i].completed = line[1].toBoolean()
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ivanloy.mentalblocks

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main_menu.*

class MainMenuActivity : AppCompatActivity(), View.OnClickListener {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main_menu)

btn_levels.setOnClickListener(this)
btn_credits.setOnClickListener(this)
btn_donations.setOnClickListener(this)
}

override fun onClick(v: View?) {
when(v!!.id){
R.id.btn_levels -> {
val intent = Intent(this, LevelListActivity::class.java)
startActivity(intent)
}
R.id.btn_donations -> {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=nachovanle@gmail.com&lc=US&item_name=YOUR+PURPOSE+HERE&no_note=0&cn=&curency_code=USD&bn=PP-DonationsBF:btn_donateCC_LG.gif:NonHosted"))
startActivity(browserIntent)
}
else -> {
Toast.makeText(this, "WIP :(", Toast.LENGTH_SHORT).show()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.ivanloy.mentalblocks;

import android.content.Context;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
* @author Sandro Machado
*/
public class SerializableManager {

/**
* Saves a serializable object.
*
* @param context The application context.
* @param objectToSave The object to save.
* @param fileName The name of the file.
* @param <T> The type of the object.
*/

public static <T extends Serializable> void saveSerializable(Context context, T objectToSave, String fileName) {
try {
FileOutputStream fileOutputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE);
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);

objectOutputStream.writeObject(objectToSave);

objectOutputStream.close();
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Loads a serializable object.
*
* @param context The application context.
* @param fileName The filename.
* @param <T> The object type.
*
* @return the serializable object.
*/

public static<T extends Serializable> T readSerializable(Context context, String fileName) {
T objectToReturn = null;

try {
FileInputStream fileInputStream = context.openFileInput(fileName);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
objectToReturn = (T) objectInputStream.readObject();

objectInputStream.close();
fileInputStream.close();
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}

return objectToReturn;
}

/**
* Removes a specified file.
*
* @param context The application context.
* @param filename The name of the file.
*/

public static void removeSerializable(Context context, String filename) {
context.deleteFile(filename);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MentalBlocks2/app/src/main/res/drawable/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MentalBlocks2/app/src/main/res/drawable/quit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions MentalBlocks2/app/src/main/res/layout/activity_level_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<ImageView
android:layout_width="50dp"
android:layout_height="50dp" app:srcCompat="@drawable/back_arrow"
android:id="@+id/imageView2"
android:id="@+id/btn_goBackToMain"
android:clickable="true"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/guideline8" android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
Expand All @@ -47,9 +48,9 @@
android:layout_height="wrap_content"
android:id="@+id/textView" android:textSize="36sp"
android:textColor="@color/darkGray" android:textStyle="bold|italic" android:textAllCaps="false"
app:layout_constraintStart_toEndOf="@+id/imageView2" android:layout_marginStart="16dp"
android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/view5125"/>
app:layout_constraintStart_toEndOf="@+id/btn_goBackToMain"
android:layout_marginStart="16dp" app:layout_constraintBottom_toTopOf="@+id/view5125"
android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent" android:layout_marginBottom="8dp"/>
<TextView
android:text="0 / 12"
android:layout_width="wrap_content"
Expand Down
44 changes: 44 additions & 0 deletions MentalBlocks2/app/src/main/res/layout/activity_main_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainMenuActivity">


<ImageView
android:layout_width="213dp"
android:layout_height="333dp" app:srcCompat="@drawable/logo"
android:id="@+id/imageView" android:layout_marginTop="32dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"/>
<ImageView
android:layout_width="336dp"
app:srcCompat="@drawable/levels"
android:id="@+id/btn_levels"
android:clickable="true"
android:layout_height="70dp"
app:layout_constraintTop_toBottomOf="@+id/imageView"
app:layout_constraintBottom_toTopOf="@+id/btn_donations"
app:layout_constraintVertical_chainStyle="packed" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
<ImageView
android:layout_width="336dp"
android:layout_height="70dp" app:srcCompat="@drawable/donations"
android:id="@+id/btn_donations"
app:layout_constraintTop_toBottomOf="@+id/btn_levels"
app:layout_constraintBottom_toTopOf="@+id/btn_credits" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"/>
<ImageView
android:layout_width="336dp"
android:layout_height="67dp" app:srcCompat="@drawable/credits"
android:id="@+id/btn_credits"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toBottomOf="@+id/btn_donations"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions MentalBlocks2/app/src/main/res/layout/level_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
app:layout_constraintEnd_toEndOf="parent"/>

<ImageView
android:layout_width="25dp"
android:layout_height="25dp" app:srcCompat="@drawable/level_completed"
android:layout_width="30dp"
android:layout_height="30dp" app:srcCompat="@drawable/level_completed"
android:id="@+id/img_levelCompleted"
android:visibility="invisible"
android:layout_marginTop="8dp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file modified MentalBlocks2/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified MentalBlocks2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#FFFFFF</color>
</resources>

0 comments on commit 3c192c0

Please sign in to comment.