Commit a9c1be32 by Joosep L

Added Readme

Added readme with basic info on how to start the application, app/build/outputs/apk has a app-debug.apk that should work on all Android devices with API version greater than 19
parent fca6279a
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
# Mobile application to support treasure hunts
Clone or download the repository.
Simplest way to test would be via Android Studio.
## Importing Project into Android Studio
You should be able to import the project directly into Android Studio:
+ Start Android Studio
+ File=>New=>Import Project
+ Press Ok and wait for all the tasks to complete
......@@ -7,7 +7,7 @@ package ee.ttu.thesis.data.network;
public final class ApiEndPoint {
//
public static final String BASE_URL = "http://127.0.0.1/api";
public static final String BASE_URL = "http://128.199.63.125/api";
public static final String ENDPOINT_GET_GAMES = BASE_URL
+ "/user/games";
......
......@@ -3,6 +3,8 @@ package ee.ttu.thesis.ui.list;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
......@@ -11,12 +13,18 @@ import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.orhanobut.logger.Logger;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import ee.ttu.thesis.R;
import ee.ttu.thesis.data.model.Game;
/**
* Created by hajola on 18.04.17.
......@@ -30,14 +38,22 @@ public class AddGameDialogFragment extends DialogFragment implements TextView.On
Button mCancel;
@BindView(R.id.dialog_add_new_game_ok_button)
Button mOk;
@BindView(R.id.dialog_enter_new_game_root)
LinearLayout mRoot;
TextView mHeader, mTitle;
String gameCode = "";
Game mGame = null;
OnGameAddListener listener;
public interface OnGameAddListener {
void onFinishEditDialog(String gameName);
void onGameCodeChangedDialog(String gameName, boolean adding);
}
public AddGameDialogFragment() {
}
public AddGameDialogFragment() {}
public static AddGameDialogFragment newInstance() {
Bundle args = new Bundle();
......@@ -53,8 +69,7 @@ public class AddGameDialogFragment extends DialogFragment implements TextView.On
@OnClick(R.id.dialog_add_new_game_ok_button)
public void onOkClicked(View v){
OnGameAddListener listener = (OnGameAddListener) getActivity();
listener.onFinishEditDialog(mEditText.getText().toString());
listener.onGameCodeChangedDialog(mEditText.getText().toString(), true);
dismiss();
}
......@@ -64,12 +79,14 @@ public class AddGameDialogFragment extends DialogFragment implements TextView.On
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_enter_new_game, container);
ButterKnife.bind(this, v);
mOk.setVisibility(View.INVISIBLE);
return v;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
listener = (OnGameAddListener) getActivity();
mEditText.setOnEditorActionListener(this);
......@@ -77,6 +94,50 @@ public class AddGameDialogFragment extends DialogFragment implements TextView.On
getDialog().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
gameCode = s.toString();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
gameCode = s.toString();
if (gameCode.length() == 0) {
loadGames(null);
} else {
listener.onGameCodeChangedDialog(gameCode, false);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
public void loadGames(List<Game> games) {
if(games == null || games.size() < 1) {
mRoot.removeAllViews();
mHeader = null;
mTitle = null;
mOk.setVisibility(View.INVISIBLE);
return;
}
mOk.setVisibility(View.VISIBLE);
mGame = games.get(0);
LinearLayout ll = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.layout_add_game, null);
mTitle = (TextView) ll.findViewById(R.id.dialog_enter_new_game_title);
mHeader = (TextView) ll.findViewById(R.id.dialog_enter_new_game_header);
mRoot.addView(ll);
mTitle.setText(mGame.getTitle());
// if(mGame.isPast())
// cant add a game, if you werent part of it
// leave it for test purposes
}
......@@ -85,7 +146,7 @@ public class AddGameDialogFragment extends DialogFragment implements TextView.On
if (EditorInfo.IME_ACTION_DONE == actionId) {
// Return input text back to activity through the implemented listener
OnGameAddListener listener = (OnGameAddListener) getActivity();
listener.onFinishEditDialog(mEditText.getText().toString());
listener.onGameCodeChangedDialog(mEditText.getText().toString(), true);
// Close the dialog and return back to the parent activity
dismiss();
return true;
......
......@@ -112,7 +112,7 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override
public int getItemViewType(int position) {
if(position == mObjects.size()-1)
if(mObjects.get(position) instanceof String && ((String) mObjects.get(position)).toLowerCase().equals("logout"))
return BUTTON;
else if(mObjects.get(position) instanceof String)
return CATEGORY_TITLE;
......
......@@ -66,6 +66,7 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
List<UserGame> mUserGames = new ArrayList<>();
GoogleApiClient mGoogleApiClient;
AddGameDialogFragment addGameDialogFragment;
User mUser;
......@@ -192,15 +193,17 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
@OnClick(R.id.floatingActionButton)
public void onFabClick(View v) {
FragmentManager fm = getSupportFragmentManager();
AddGameDialogFragment addGameDialogFragment = AddGameDialogFragment.newInstance();
addGameDialogFragment = AddGameDialogFragment.newInstance();
addGameDialogFragment.show(fm, "fragment_add_game");
}
@Override
public void onFinishEditDialog(String gameName) {
Toast.makeText(this, gameName, Toast.LENGTH_SHORT).show();
public void onGameCodeChangedDialog(String gameName, boolean adding) {
if(adding)
mPresenter.onAddGame(new GamesRequest.AddGameRequest(mUser.getId(), gameName));
else
mPresenter.getGame(gameName);
}
@Override
......@@ -229,7 +232,7 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
}
@Override
public void loadGames(List<UserGame> response) {
public void loadUserGames(List<UserGame> response) {
Logger.d("response length: " + response.size());
mUserGames = response;
......@@ -287,20 +290,20 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
for (Object o : mObjects) {
if (o instanceof String) {
if (o.equals("Upcoming")) {
mObjects.add(mObjects.indexOf(o), game);
mObjects.add(mObjects.indexOf(o)-1, game);
mAdapter.notifyDataSetChanged();
return;
}
if (o.equals("Past")) {
mObjects.add(mObjects.indexOf(o), game);
mObjects.add(mObjects.indexOf(o), "Upcoming");
mObjects.add(mObjects.indexOf(o)-1, game);
mObjects.add(mObjects.indexOf(o)-1, "Upcoming");
mAdapter.notifyDataSetChanged();
return;
}
}
}
mObjects.add(mObjects.size(), "Upcoming");
mObjects.add(mObjects.size(), game);
mObjects.add(mObjects.size()-1, "Upcoming");
mObjects.add(mObjects.size()-1, game);
} else {
......@@ -323,6 +326,14 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
}
@Override
public void showgames(List<Game> games) {
if(addGameDialogFragment != null && addGameDialogFragment.isVisible())
addGameDialogFragment.loadGames(games);
}
@Override
public void onConnected(@Nullable Bundle bundle) {
}
......
......@@ -5,6 +5,7 @@ import java.util.List;
import javax.inject.Inject;
import ee.ttu.thesis.data.DataManager;
import ee.ttu.thesis.data.model.Game;
import ee.ttu.thesis.data.model.GamesRequest;
import ee.ttu.thesis.data.model.UserGame;
import ee.ttu.thesis.ui.base.BasePresenter;
......@@ -42,7 +43,7 @@ public class ListPresenter<V extends ListView> extends BasePresenter<V> implemen
}
if (userGames != null) {
getmThesisView().loadGames(userGames);
getmThesisView().loadUserGames(userGames);
}
}
}, new Consumer<Throwable>() {
......@@ -84,6 +85,28 @@ public class ListPresenter<V extends ListView> extends BasePresenter<V> implemen
}
@Override
public void getGame(String gameCode) {
getCompositeDisposable().add(getDataManager()
.getGame(gameCode)
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
.subscribe(new Consumer<List<Game>>() {
@Override
public void accept(@NonNull List<Game> games) throws Exception {
if (!isViewAttached()) {
return;
}
getmThesisView().showgames(games);
}
}, new Consumer<Throwable>() {
@Override
public void accept(@NonNull Throwable throwable) throws Exception {
getmThesisView().onError(throwable.getMessage());
}
}));
}
@Override
public String getService() {
return getDataManager().getService();
}
......
......@@ -15,6 +15,8 @@ public interface ListTreasureHuntPresenter<V extends ListView> extends TreauseHu
void onAddGame(GamesRequest.AddGameRequest userGamesRequest);
void getGame(String gameCode);
String getService();
String getGameCode();
......
......@@ -2,6 +2,7 @@ package ee.ttu.thesis.ui.list;
import java.util.List;
import ee.ttu.thesis.data.model.Game;
import ee.ttu.thesis.data.model.UserGame;
import ee.ttu.thesis.ui.base.TreasureHuntView;
......@@ -11,8 +12,10 @@ import ee.ttu.thesis.ui.base.TreasureHuntView;
public interface ListView extends TreasureHuntView {
void loadGames(List<UserGame> response);
void loadUserGames(List<UserGame> response);
void addGame(UserGame response);
void showgames(List<Game> games);
}
......@@ -5,7 +5,6 @@
android:background="@color/colorPrimaryDark"
android:gravity="top|center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="60dp"
android:paddingRight="60dp"
android:paddingTop="@dimen/activity_vertical_margin"
......@@ -42,8 +41,8 @@
fontPath="fonts/amatic.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="64dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="48dp"
android:layout_marginTop="48dp"
android:text="Join the game!"
android:textAlignment="center"
android:textColor="@color/colorAccent"
......@@ -108,7 +107,7 @@
android:id="@+id/activity_login_enter_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="48dp"
android:layout_marginBottom="32dp"
android:background="@drawable/rounded_rectangle"
android:text="enter"
android:textAllCaps="false"
......@@ -161,8 +160,9 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_height="80dp"
android:layout_marginBottom="12dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
......@@ -170,7 +170,6 @@
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginRight="32dp"
android:background="@drawable/circle_login_icons"
android:elevation="6dp"
......@@ -183,9 +182,7 @@
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:background="@drawable/circle_login_icons"
android:elevation="6dp"
android:padding="24dp"
......
......@@ -5,6 +5,14 @@
android:background="@color/colorPrimaryDark"
android:orientation="vertical">
<LinearLayout
android:id="@+id/dialog_enter_new_game_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
<EditText
android:id="@+id/dialog_enter_new_game_editText"
android:layout_width="match_parent"
......@@ -44,7 +52,7 @@
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:background="@android:color/transparent"
android:text="OK"
android:text="ADD"
android:textColor="@color/colorAccent" />
</RelativeLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginTop="64dp"
android:orientation="vertical">
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/dialog_enter_new_game_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:text="Title"
android:textColor="@color/colorSecondaryMain" />
<TextView
android:id="@+id/dialog_enter_new_game_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text=""
android:textAlignment="textStart"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment