Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

android {
Expand Down Expand Up @@ -32,9 +34,11 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.jakewharton:butterknife:8.4.0'
kapt "com.jakewharton:butterknife-compiler:8.4.0"
compile 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile "io.reactivex.rxjava2:rxjava:2.1.1"
Expand All @@ -44,4 +48,5 @@ dependencies {
compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
compile 'com.facebook.stetho:stetho:1.5.0'
compile 'com.uphyca:stetho_realm:2.2.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
2 changes: 1 addition & 1 deletion app/src/main/java/castofo/com/co/nower/Nower.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void onCreate() {
Realm.init(this);

RealmConfiguration config = new RealmConfiguration.Builder()
.schemaVersion(6) // Must be manually bumped when the schema changes.
.schemaVersion(7) // Must be manually bumped when the schema changes.
.migration(new LocalMigrationManager())
.build();
Realm.setDefaultConfiguration(config);
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/castofo/com/co/nower/location/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
Expand All @@ -37,14 +39,19 @@
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

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

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import castofo.com.co.nower.R;
import castofo.com.co.nower.models.Branch;
import castofo.com.co.nower.models.ContactInformation;
import castofo.com.co.nower.models.Promo;
import castofo.com.co.nower.models.Store;
import castofo.com.co.nower.utils.DialogCreatorHelper;
import castofo.com.co.nower.views.adapters.BranchPromosAdapter;
import io.realm.RealmList;

import static castofo.com.co.nower.utils.RequestCodeHelper.ENABLE_GPS_REQUEST_CODE;
Expand Down Expand Up @@ -93,6 +100,8 @@ public class MapActivity extends AppCompatActivity implements OnMapReadyCallback
AppCompatTextView tvBranchContactInfoPhone;
@BindView(R.id.tv_branch_contact_info_email)
AppCompatTextView tvBranchContactInfoEmail;
@BindView(R.id.rv_branch_promos)
RecyclerView rvBranchPromos;
@BindView(R.id.pb_branch_promos_progress)
ProgressBar pbBranchPromosProgress;

Expand All @@ -102,6 +111,7 @@ public class MapActivity extends AppCompatActivity implements OnMapReadyCallback
private BottomSheetBehavior mBranchContainer;
private Marker mCurrentMarker;
private Branch mCurrentBranch;
private BranchPromosAdapter mBranchPromosAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -118,6 +128,8 @@ protected void onCreate(Bundle savedInstanceState) {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

setupBranchPromosRecycler();
}

/**
Expand Down Expand Up @@ -485,6 +497,13 @@ public void hideLoadingBranchPromosProgress() {
pbBranchPromosProgress.setVisibility(View.GONE);
}

@Override
public void populateBranchPromos(List<Promo> promos) {
mBranchPromosAdapter.getPromos().clear();
mBranchPromosAdapter.getPromos().addAll(promos);
mBranchPromosAdapter.notifyDataSetChanged();
}

/**
* Shows a dialog containing the opening times of the selected Branch.
*/
Expand All @@ -503,6 +522,20 @@ public void onBranchStatusClick() {
getResources().getString(R.string.label_opening_times));
}

private void setupBranchPromosRecycler() {
rvBranchPromos.setLayoutManager(new LinearLayoutManager(this));

mBranchPromosAdapter = new BranchPromosAdapter(new ArrayList<>(), promo -> {
onPromoClick(promo);
return null;
});
rvBranchPromos.setAdapter(mBranchPromosAdapter);
}

private void onPromoClick(Promo promo) {
// TODO: Implement transition to promo details.
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.location.Location;
import android.support.design.widget.BottomSheetBehavior;
import android.util.Log;
import android.view.View;

import com.google.android.gms.maps.model.LatLng;
Expand Down Expand Up @@ -258,7 +257,6 @@ public void onLoadingBranchError(Throwable throwable) {
@Override
public void onLoadingBranchSuccess(Branch loadedBranch) {
if (mMapView != null) {
Log.i(TAG, "Branch name: " + loadedBranch.getName());
mMapView.populateBranchInfo(loadedBranch);
}
}
Expand All @@ -285,12 +283,8 @@ public void onLoadingBranchPromosSuccess(String branchId, List<Promo> branchProm
// The user is currently watching the same Branch from which he requested the Promo list.
if (branchPromoList.isEmpty()) {
// mMapView.showNoBranchPromosMessage(); TODO
Log.i(TAG, "showNoBranchPromosMessage");
} else {
for (Promo promo : branchPromoList) {
// mMapView.addPromoToBranch(promo); TODO
Log.i(TAG, "addPromoToBranch(promo)");
}
mMapView.populateBranchPromos(branchPromoList);
}
mMapView.hideLoadingBranchPromosProgress();
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/castofo/com/co/nower/location/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;

import java.util.List;

import castofo.com.co.nower.models.Branch;
import castofo.com.co.nower.models.Promo;

/**
* Created by Alejandro on 19/09/2016.
Expand Down Expand Up @@ -67,4 +70,6 @@ public interface MapView {
void showLoadingBranchPromosError();

void hideLoadingBranchPromosProgress();

void populateBranchPromos(List<Promo> promos);
}
98 changes: 0 additions & 98 deletions app/src/main/java/castofo/com/co/nower/models/Promo.java

This file was deleted.

29 changes: 29 additions & 0 deletions app/src/main/java/castofo/com/co/nower/models/Promo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package castofo.com.co.nower.models

import com.google.gson.annotations.SerializedName

import io.realm.RealmObject
import io.realm.RealmResults
import io.realm.annotations.LinkingObjects
import io.realm.annotations.PrimaryKey
import io.realm.annotations.Required

/**
* Created by Santiago Vanegas on 12/9/17.
*/
open class Promo(
@PrimaryKey
@Required
var id: String? = null,
var name: String? = null,
var description: String? = null,
var terms: String? = null,
var stock: Int? = null,
var price: Float? = null,
@SerializedName("start_date")
var startDate: String? = null,
@SerializedName("end_date")
var endDate: String? = null,
@LinkingObjects("promos")
val branches: RealmResults<Branch>? = null
) : RealmObject()
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,15 @@ public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
Log.i(TAG, "DB migrated from version " + (oldVersion - 1) + " to version " + oldVersion
+ ".");
}

// Stock and price in Promo are now optional, so that they can support null values.
if (oldVersion == 6) {
schema.get("Promo")
.setRequired("stock", false)
.setRequired("price", false);
oldVersion++;
Log.i(TAG, "DB migrated from version " + (oldVersion - 1) + " to version " + oldVersion
+ ".");
}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package castofo.com.co.nower.views.adapters

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import butterknife.ButterKnife
import castofo.com.co.nower.R
import castofo.com.co.nower.models.Promo

/**
* Created by Santiago Vanegas Gil on 12/9/17.
*/
class BranchPromosAdapter(val promos: List<Promo>, private val listener: (Promo) -> Unit) :
RecyclerView.Adapter<BranchPromosAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.promo_item, parent, false)
return ViewHolder(view, listener)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int)
= holder.bind(promos[position])

override fun getItemCount() = promos.size

class ViewHolder(view: View, private val listener: (Promo) -> Unit) :
RecyclerView.ViewHolder(view) {

fun bind(promo: Promo) = with(promo) {
ButterKnife.findById<TextView>(itemView, R.id.promo_title).text = name
ButterKnife.findById<TextView>(itemView, R.id.promo_subtitle).text = stock?.toString()
ButterKnife.findById<TextView>(itemView, R.id.promo_description).text = description
itemView.setOnClickListener { listener(this) }
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/bottom_sheet_branch_container.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_branch_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -247,6 +248,14 @@
android:layout_marginTop="@dimen/branch_section_padding"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv_branch_promos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/global_spacing_8"
android:scrollbars="vertical"
tools:listitem="@layout/promo_item"/>

<ProgressBar
android:id="@+id/pb_branch_promos_progress"
android:layout_width="wrap_content"
Expand Down
Loading