Skip to content

joe-kramer/ClashOfClansPlayerLook

Repository files navigation

Clash of Clans - Clan lookup

AWS:

The clash of clans api documentation requires you to register your IP address to receive your key. This leads to problems (with moble development especially) because our IP is always changing. To work around this, I created an AWS VPC and associated an elastic IP. Then by configuring my Lambda function, which runs my api call, to run through this IP, I can call this Lambda function from anywhere and recieve a successful response.

Resources:

A VPC with:
  • Public Subnet
  • Private Subnet
  • NAT Gateway
  • Elastic IP
  • 2 Routes (public/private)
  • Internet Gateway
Lambda
API Gateway

VPC Configuration:

  • Create a VPC
  • Create two subnets (private/public)
  • Create Internet Gateway
  • Attach igw to VPC to enable communication with the internet.
  • Create public route table and link it to VPC
  • point new route at igw
  • Associate route with public subnet
  • Create NAT gateway
  • Create an elastic IP
  • Assign new elastic IP with NAT gateway
  • Edit default route and set all traffic (0.0.0.0/0) to target our nat instance id

Lambda and API Gateway Configuration:

  • Create a lambda function with the blueprint "microservice-http-endpoint"
  • Create Role and configure VPC setttings
  • When you enable VPC, your Lambda function will lose default internet access. If you require external internet access for your function, ensure that your security group allows outbound connections and that your VPC has a NAT gateway.
  • Deploy Api
  • Call api from android, inputting clanTag input as query parameter

App:

Setup

  • Clone down app
  • Open in android studio
  • Run on emulator (Nexus 6P API 26)
  • Create user and login
  • Input clan tag into input on first page (see tags at bottom of README)
  • ClanTag is passed to service
  • ClanTag urlEncoded
  • Api call is made through api gateway to AWS Lambda function and returns JSON result

App Features

Input Validation

  • create new textchangelistener on our editText that creates a new TestWatcher
  • Inside TextWatcher, validate code on text change
  • _If code matches regex .[^A-Z^0-9^#]. user will be prompted with a toast, telling them the correct format
  • ---Validation on button for length---

API Call To Get Clan JSON

  • Clan tag input is declared query parameter to AWS API Gateway url
  • Call made to AWS API Gateway, which calls our AWS Lambda Function
  • AWS Lambda function makes api call in node.js to Clash of Clans API
  • AWS Lambda function is sent to public subnet of my AWS VPC
  • API call now comes from our Elastic IP address in our VPC
  • JSON is sent back down chain to android

API - On Response

  • _On API response, use runOnUiThread function, and inside set our displayed clan views. This must be done in this function to merge our "API work thread" with our UI(Main) thread.
  • Set picture and resize using Picasso

Menu Items

  • Logout - Logs User out from App
  • Save - Save a clan to firebase under your registered account

Saved Clans List View

  • Reuse our memberlist recyclerView and layout as our new View in SavedClansListActivity
  • Create custom saved_clan_list_item.xml view for a new FirebaseClanViewHolder
  • Pass our custom FirebaseClanViewHolder into our mFirebaseAdapter
  • Set our RecyclerView to use our newly configured mFirebaseAdapter
  • When the activity is destroyed, cleanup() is called on the adapter so that it will stop listening for changes in Firebase.

NavBar

Login

  • Create instance of FirebaseAuth
  • Validate email and password
  • Authenticate user with built-in firebase method called signInWithEmailAndPassword()
  • On complete, if Authenitication is successful, we will send intent to Main Activity from AuthStateListener

Register User

Progress Dialogs

  • In CreateAccountActivity, dismissed onComplete in firebase createUserWithEmailAndPassword method
  • In LoginActivity, dismissed onComplete of firebase signInWithEmailAndPassword method

Firebase Database

  • Array named clans, composed of nodes for each User
  • Each User has a Node using their unique uid key
  • push saved Clan's into associated User's node
  • Clan push Id also saved as attribute

Shared Preferences

  • Used to save last user logged in, displays users username next time they visit the login page

Custom Fragments

#####Number steps??

  • Fragments are "The component of the android world"
  • Our MemberDetailFragment will be display a members details after being clicked in our Members ListView
  • The ViewPager in the MemberDetailActivity acts as the container for our fragment
  • The PagerTabStrip in the MemberDetailActivity will create a header at the top of our ViewPager which will display the current Members name
  • To pass the Member information to fragment, the information must be Serialized (the conversion of an object into bytes)
  • In our MemberDetailFragment constructor, we will wrap our Member object in a Parcelable and put in bundle
  • Bundle will be associated with our new memberDetailFragement
  • OnCreate of our MemberDetailFragment, we unwrap our Parcel and create our view based on this Deserialized Member Object
  • We set our PagerTabStrip with the MemberPagerAdapter
  • The list of Members is wrapped in a Parcelable in our ClanActivity, then sent and unwrapped in our MemberDetailActivity to complete processes listed above
Sample ClanTags
  • #G9J8PL8Q
  • #QGJY8UR
  • #PO8RVRV9

About

Android app using the clash of clans api to look up personal stats

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages