Skip to content

Commit

Permalink
Add base application code
Browse files Browse the repository at this point in the history
  • Loading branch information
fzy-github committed Sep 6, 2015
1 parent 144f80f commit ba311d3
Show file tree
Hide file tree
Showing 54 changed files with 1,694 additions and 17 deletions.
33 changes: 29 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "meet.mobile.tv"
minSdkVersion 22
targetSdkVersion 23
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -21,4 +29,21 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.google.dagger:dagger:2.0.1'

apt 'com.google.dagger:dagger-compiler:2.0.1'
}

retrolambda {
jdk System.getenv("JAVA8_HOME")
oldJdk System.getenv("JAVA7_HOME")
javaVersion JavaVersion.VERSION_1_7
}
27 changes: 21 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="meet.mobile.tv">
package="meet.mobile" >

<application android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />

</application>
<application
android:name=".application.AdvancedRecyclerViewApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
Binary file added app/src/main/ic_refresh-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions app/src/main/java/meet/mobile/activity/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package meet.mobile.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import javax.inject.Inject;

import meet.mobile.application.AdvancedRecyclerViewApplication;
import meet.mobile.dagger.componentes.ApplicationComponent;
import meet.mobile.dagger.modules.ActivityModule;


/**
* Created by Filip Zymek on 2015-06-19.
*/
public abstract class BaseActivity extends AppCompatActivity {

@Inject
protected DisplayImageOptions options;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getApplicationComponent().inject(this);
}

public DisplayImageOptions getDisplayImageOptions() {
return options;
}

protected ApplicationComponent getApplicationComponent() {
return ((AdvancedRecyclerViewApplication)getApplication()).getApplicationComponent();
}

protected ActivityModule getActivityModule() {
return new ActivityModule(this);
}
}
62 changes: 62 additions & 0 deletions app/src/main/java/meet/mobile/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package meet.mobile.activity;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.MenuItem;

import meet.mobile.R;
import meet.mobile.fragment.MainFragment;


public class MainActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupPreferences();

if (savedInstanceState == null) {
Log.d("main", "attaching fragment");
MainFragment f = MainFragment.newInstance();
getFragmentManager().beginTransaction()
.replace(R.id.content_frame, f, "main")
.commit();
} else {
Log.d("main", "no fragment");
}

}

@Override
public void onBackPressed() {
if (getFragmentManager().getBackStackEntryCount() > 0) {
getFragmentManager().popBackStack();
} else {
super.onBackPressed();
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

switch (id) {
case android.R.id.home:
onBackPressed();
return true;

}
return super.onOptionsItemSelected(item);
}


private void setupPreferences() {
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
}

}
151 changes: 151 additions & 0 deletions app/src/main/java/meet/mobile/adapter/ImagesAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package meet.mobile.adapter;

import android.animation.TimeInterpolator;
import android.content.Context;
import android.graphics.Point;
import android.support.v7.widget.RecyclerView;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.DecelerateInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import meet.mobile.R;
import meet.mobile.model.Image;

import static meet.mobile.utils.Utils.isLandscape;


/**
* Created by Filip Zymek on 2015-06-22.
*/
public class ImagesAdapter extends RecyclerView.Adapter<ImagesAdapter.ImageCard> {

final List<Image> images = new ArrayList<>();
final TimeInterpolator interpolator = new DecelerateInterpolator(2);
final SparseBooleanArray animatedPositions = new SparseBooleanArray();
final Point windowSize = new Point();
final DisplayImageOptions options;

Context context;
int lastPosition = 0;

public ImagesAdapter(Context context, DisplayImageOptions options) {
this.context = context;
this.options = options;

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getSize(windowSize);

}

@Override
public ImageCard onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(this.context).inflate(R.layout.image_card, parent, false);
return new ImageCard(v);
}

@Override
public void onBindViewHolder(final ImageCard holder, int position) {
holder.artist.setText(getItem(position).getArtist());
holder.title.setText(getItem(position).getTitle());
ImageLoader.getInstance().cancelDisplayTask(holder.image);
ImageLoader.getInstance().displayImage(getItem(position).getDisplayByType(Image.DisplaySizeType.PREVIEW).getUri(), holder.image, options);

if (position > lastPosition && !animatedPositions.get(position)) {
lastPosition = position;
animatedPositions.put(position, true);
startItemAnimation(holder, position);
}
}

private void startItemAnimation(ImageCard holder, int position) {
setupCommonItemProperties(holder);

if (isLandscape(context)) {
setupHorizontalItemProperties(holder, position);
} else {
setupVerticalItemProperties(holder);
}

holder.itemView.animate().translationX(0)
.translationY(0)
.rotationX(0)
.rotationY(0)
.scaleX(1)
.scaleY(1)
.alpha(1)
.setDuration(500)
.setInterpolator(interpolator)
.setStartDelay(0)
.start();
}

private Image getItem(int position) {
return images.get(position);
}

@Override
public int getItemCount() {
return images.size();
}

public void setImages(List<Image> images) {
this.images.clear();
this.images.addAll(images);
notifyDataSetChanged();
}

public void clear() {
this.images.clear();
lastPosition = 0;
animatedPositions.clear();
notifyDataSetChanged();
}

private void setupCommonItemProperties(ImageCard holder) {
holder.itemView.setTranslationX(0);
holder.itemView.setTranslationY(windowSize.y);
holder.itemView.setScaleX(0.6f);
holder.itemView.setScaleY(0.6f);
holder.itemView.setAlpha(0);
}

private void setupHorizontalItemProperties(ImageCard holder, int position) {
if (position % 2 == 0) {
holder.itemView.setRotationY(45.0f);
} else {
holder.itemView.setRotationY(-45.0f);
}
}

private void setupVerticalItemProperties(ImageCard holder) {
holder.itemView.setRotationX(45.0f);
}

protected static class ImageCard extends RecyclerView.ViewHolder {

@InjectView(R.id.image)
ImageView image;
@InjectView(R.id.artist)
TextView artist;
@InjectView(R.id.title)
TextView title;

public ImageCard(View itemView) {
super(itemView);
ButterKnife.inject(this, itemView);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package meet.mobile.application;

import android.app.Application;

import meet.mobile.dagger.componentes.ApplicationComponent;
import meet.mobile.dagger.componentes.DaggerApplicationComponent;
import meet.mobile.dagger.modules.ApplicationModule;


/**
* Created by Filip Zymek on 2015-06-19.
*/
public class AdvancedRecyclerViewApplication extends Application {

private ApplicationComponent applicationComponent;

@Override
public void onCreate() {
super.onCreate();

this.applicationComponent = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this))
.build();
}

public ApplicationComponent getApplicationComponent() {
return applicationComponent;
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/meet/mobile/config/API.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package meet.mobile.config;

/**
* Created by Filip Zymek on 2015-06-08.
*/
public class API {

//gettyimages secrets
public static final String CONSUMER_KEY = "66tk2kux2g9fygcuj8eemmtf";
public static final String GETTY_IMAGES_SEARCH_ENDPOINT = "https://api.gettyimages.com/v3";

}
10 changes: 10 additions & 0 deletions app/src/main/java/meet/mobile/config/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package meet.mobile.config;

/**
* Created by Filip Zymek on 2015-06-09.
*/
public interface Config {
String KEY_PREF_FAV_ANIMAL = "fav_animal";
String PREF_FAV_ANIMAL_DEFAULT = "1";
String KEY_PREF_USE_STAGGERED_GRID = "use_staggered_grid";
}
Loading

0 comments on commit ba311d3

Please sign in to comment.