Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merged release-0.5 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Jan 5, 2017
2 parents 9fe1d07 + ef178d5 commit f6b09e1
Show file tree
Hide file tree
Showing 111 changed files with 3,265 additions and 773 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ before_script:
- cp opencv/build/lib/libopencv_java310.so opencv_lib/libopencv_java310.so
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/opencv_lib/
- chmod +x gradlew
# Create gradle.properties with fake credentials
- echo "OpenWeatherMapApiKey=\"c75f70c4717eb95847d378bba3bdb275\"" > ~/.gradle/gradle.properties

script:
# Compile and run unit tests
Expand Down
11 changes: 9 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.davidmiguel.gobees"
minSdkVersion 19
targetSdkVersion 25
versionCode 4
versionName "v0.4"
versionCode 5
versionName "v0.5"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand All @@ -33,6 +33,11 @@ android {
}
}

buildTypes.each {
// OpenWeatherMap key (stored in [USER_HOME]/.gradle/gradle.properties)
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', OpenWeatherMapApiKey
}

// Mock: stubs out the service layer completely and returns a fake dataset
// Prod: production version
productFlavors {
Expand Down Expand Up @@ -84,13 +89,15 @@ dependencies {
compile 'com.makeramen:roundedimageview:2.3.0'
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
compile 'com.vanniktech:vntnumberpickerpreference:1.0.0'
compile 'rebus:permission-utils:1.0.6'

// Dependencies for local unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:2.0.2-beta'
testCompile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'org.slf4j:slf4j-log4j12:1.7.21'
testCompile 'log4j:log4j:1.2.17'
testCompile 'org.json:json:20160810'

// Android Testing Support Library's runner and rules
androidTestCompile 'com.android.support.test:runner:0.5'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>

<uses-feature android:name="android.hardware.camera"/>
<uses-feature
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.davidmiguel.gobees.addeditapiary;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
Expand All @@ -18,6 +20,7 @@ public class AddEditApiaryActivity extends AppCompatActivity {
public static final int REQUEST_ADD_APIARY = 1;
public static final int NEW_APIARY = -1;

private Fragment addEditApiaryFragment;
private GoBeesRepository goBeesRepository;

@Override
Expand All @@ -39,9 +42,7 @@ protected void onCreate(Bundle savedInstanceState) {
.getLongExtra(AddEditApiaryFragment.ARGUMENT_EDIT_APIARY_ID, NEW_APIARY);

// Add fragment to the activity and set title
AddEditApiaryFragment addEditApiaryFragment =
(AddEditApiaryFragment) getSupportFragmentManager()
.findFragmentById(R.id.contentFrame);
addEditApiaryFragment = getSupportFragmentManager().findFragmentById(R.id.contentFrame);
if (addEditApiaryFragment == null) {
addEditApiaryFragment = AddEditApiaryFragment.newInstance();
if (getIntent().hasExtra(AddEditApiaryFragment.ARGUMENT_EDIT_APIARY_ID)) {
Expand All @@ -67,7 +68,8 @@ protected void onCreate(Bundle savedInstanceState) {
goBeesRepository.openDb();

// Create the presenter
new AddEditApiaryPresenter(goBeesRepository, addEditApiaryFragment, apiaryId);
new AddEditApiaryPresenter(goBeesRepository,
(AddEditApiaryContract.View) addEditApiaryFragment, apiaryId);
}

@Override
Expand All @@ -82,4 +84,12 @@ public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (addEditApiaryFragment != null) {
addEditApiaryFragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ interface View extends BaseView<Presenter> {
* Shows save error message.
*/
void showSaveApiaryError();

/**
* Checks whether ACCESS_FINE_LOCATION permission is granted. If not, asks for it.
*
* @return if the permission is granted.
*/
boolean checkLocationPermission();
}

interface Presenter extends BasePresenter {
Expand All @@ -75,7 +82,7 @@ interface Presenter extends BasePresenter {
* @param name apiary name.
* @param notes apiary notes.
*/
void saveApiary(String name, String notes);
void save(String name, String notes);

/**
* Fill apiary data (the apiary must already exist in the repository).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.davidmiguel.gobees.addeditapiary;

import android.app.Activity;
import android.content.DialogInterface;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -9,6 +10,7 @@
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -18,6 +20,12 @@

import com.davidmiguel.gobees.R;

import rebus.permissionutils.AskagainCallback;
import rebus.permissionutils.PermissionEnum;
import rebus.permissionutils.PermissionManager;
import rebus.permissionutils.PermissionUtils;
import rebus.permissionutils.SimpleCallback;

import static com.google.common.base.Preconditions.checkNotNull;

/**
Expand Down Expand Up @@ -72,11 +80,10 @@ public void onClick(View view) {
// Configure floating action button
FloatingActionButton fab =
(FloatingActionButton) getActivity().findViewById(R.id.fab_add_apiary);
fab.setImageResource(R.drawable.ic_done);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.saveApiary(nameTextView.getText().toString(),
public void onClick(View view) {
presenter.save(nameTextView.getText().toString(),
notesTextView.getText().toString());
}
});
Expand All @@ -101,13 +108,13 @@ public void setName(String name) {

@Override
public void setLocation(Location location) {
String sb = "(" +
String.valueOf(location.getLatitude()) +
", " +
String.valueOf(location.getLongitude()) +
") ±" +
Math.round(location.getAccuracy()) +
"m";
String sb = "("
+ String.valueOf(location.getLatitude())
+ ", "
+ String.valueOf(location.getLongitude())
+ ") ±"
+ Math.round(location.getAccuracy())
+ "m";
locationTextView.setText(sb);
}

Expand All @@ -118,8 +125,8 @@ public void setNotes(String notes) {

@Override
public void setLocationIcon(boolean active) {
getLocationIcon.setColorFilter(active ?
ContextCompat.getColor(getContext(), R.color.colorPrimaryDark) :
getLocationIcon.setColorFilter(active
? ContextCompat.getColor(getContext(), R.color.colorPrimaryDark) :
ContextCompat.getColor(getContext(), R.color.colorAccent));
}

Expand Down Expand Up @@ -150,6 +157,63 @@ public void showSaveApiaryError() {
showMessage(getView(), getString(R.string.save_apiary_error_message));
}

@Override
public boolean checkLocationPermission() {
// Check location permission
if (PermissionUtils.isGranted(getActivity(), PermissionEnum.ACCESS_FINE_LOCATION)) {
return true;
}
// Ask for permission
PermissionManager.with(getActivity())
.permission(PermissionEnum.ACCESS_FINE_LOCATION)
.askagain(true)
.askagainCallback(new AskagainCallback() {
@Override
public void showRequestPermission(final UserResponse response) {
new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.permission_request_title))
.setMessage(getString(R.string.location_permission_request_body))
.setPositiveButton(getString(R.string.permission_request_allow_button),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
response.result(true);
}
})
.setNegativeButton(getString(R.string.permission_request_deny_button),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
response.result(false);
}
})
.setCancelable(false)
.show();
}
})
.callback(new SimpleCallback() {
@Override
public void result(boolean allPermissionsGranted) {
if (allPermissionsGranted) {
// Launch the feature
presenter.toogleLocation(getContext());
} else {
// Warn the user that it's not possible to use the feature
Toast.makeText(getActivity(), getString(R.string.permission_request_denied),
Toast.LENGTH_LONG).show();
}
}
})
.ask();
return false;
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
PermissionManager.handleResult(requestCode, permissions, grantResults);
}

@Override
public boolean isActive() {
return isAdded();
Expand Down
Loading

0 comments on commit f6b09e1

Please sign in to comment.