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

Commit dfe9c9f

Browse files
committed
Merge branch 'release-0.2'
2 parents 785752b + 3a2c626 commit dfe9c9f

File tree

72 files changed

+3870
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3870
-702
lines changed

app/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'jacoco-android'
3+
apply plugin: 'realm-android'
34

45
android {
56
compileSdkVersion 25
@@ -9,8 +10,8 @@ android {
910
applicationId "com.davidmiguel.gobees"
1011
minSdkVersion 19
1112
targetSdkVersion 25
12-
versionCode 1
13-
versionName "0.1"
13+
versionCode 2
14+
versionName "0.2"
1415

1516
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1617
}
@@ -79,6 +80,7 @@ dependencies {
7980
compile 'com.android.support:support-v4:25.0.1'
8081
compile 'com.github.davidmigloz:opencv-android-gradle-repo:3.1.0'
8182
compile 'com.google.guava:guava:20.0'
83+
compile 'com.makeramen:roundedimageview:2.2.1'
8284

8385
// Dependencies for local unit tests
8486
testCompile 'junit:junit:4.12'

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
android:allowBackup="true"
1717
android:icon="@mipmap/ic_launcher"
1818
android:label="@string/app_name"
19+
android:name=".GoBeesApp"
1920
android:supportsRtl="true"
2021
android:theme="@style/AppTheme">
2122
<activity
@@ -26,9 +27,13 @@
2627
<category android:name="android.intent.category.LAUNCHER"/>
2728
</intent-filter>
2829
</activity>
29-
<activity android:name="com.davidmiguel.gobees.addeditapiary.AddEditApiaryActivity" />
30+
<activity android:name=".addeditapiary.AddEditApiaryActivity" />
3031
<activity
31-
android:name=".MainActivity"
32+
android:name=".hives.HivesActivity"
33+
android:parentActivityName=".apiaries.ApiariesActivity" />
34+
<activity android:name=".addedithive.AddEditHiveActivity" />
35+
<activity
36+
android:name=".premonitoring.PreMonitoringActivity"
3237
android:screenOrientation="landscape"/>
3338
</application>
3439

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.davidmiguel.gobees;
2+
3+
import android.app.Application;
4+
5+
import com.davidmiguel.gobees.data.source.local.GoBeesDbConfig;
6+
7+
import io.realm.Realm;
8+
9+
/**
10+
* Main app.
11+
*/
12+
public class GoBeesApp extends Application {
13+
@Override
14+
public void onCreate() {
15+
super.onCreate();
16+
// Initialize Realm. Should only be done once when the application starts.
17+
Realm.init(this);
18+
// Get Realm config
19+
GoBeesDbConfig realmConfig = new GoBeesDbConfig();
20+
Realm.setDefaultConfiguration(realmConfig.getRealmConfiguration());
21+
}
22+
}

app/src/main/java/com/davidmiguel/gobees/addeditapiary/AddEditApiaryActivity.java

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77

88
import com.davidmiguel.gobees.Injection;
99
import com.davidmiguel.gobees.R;
10+
import com.davidmiguel.gobees.data.source.cache.GoBeesRepository;
1011
import com.davidmiguel.gobees.utils.ActivityUtils;
1112
import com.google.common.base.Strings;
1213

1314
/**
14-
* Add / edit apiaries activity.
15+
* Add / edit apiary activity.
1516
*/
1617
public class AddEditApiaryActivity extends AppCompatActivity {
1718

1819
public static final int REQUEST_ADD_APIARY = 1;
20+
public static final int NEW_APIARY = -1;
21+
22+
private GoBeesRepository goBeesRepository;
1923

2024
@Override
2125
protected void onCreate(Bundle savedInstanceState) {
@@ -26,17 +30,14 @@ protected void onCreate(Bundle savedInstanceState) {
2630
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
2731
setSupportActionBar(toolbar);
2832
ActionBar actionBar = getSupportActionBar();
29-
actionBar.setDisplayHomeAsUpEnabled(true);
30-
actionBar.setDisplayShowHomeEnabled(true);
33+
if (actionBar != null) {
34+
actionBar.setDisplayHomeAsUpEnabled(true);
35+
actionBar.setDisplayShowHomeEnabled(true);
36+
}
3137

3238
// Get apiary id (if edit)
33-
String id = getIntent().getStringExtra(AddEditApiaryFragment.ARGUMENT_EDIT_APIARY_ID);
34-
int apiaryId;
35-
if(Strings.isNullOrEmpty(id)) {
36-
apiaryId = -1;
37-
} else {
38-
apiaryId = Integer.parseInt(id);
39-
}
39+
long apiaryId = getIntent()
40+
.getLongExtra(AddEditApiaryFragment.ARGUMENT_EDIT_APIARY_ID, NEW_APIARY);
4041

4142
// Add fragment to the activity and set title
4243
AddEditApiaryFragment addEditApiaryFragment =
@@ -46,22 +47,35 @@ protected void onCreate(Bundle savedInstanceState) {
4647
addEditApiaryFragment = AddEditApiaryFragment.newInstance();
4748
if (getIntent().hasExtra(AddEditApiaryFragment.ARGUMENT_EDIT_APIARY_ID)) {
4849
// If edit -> set edit title
49-
actionBar.setTitle(R.string.edit_apiary);
50+
if (actionBar != null) {
51+
actionBar.setTitle(R.string.edit_apiary);
52+
}
5053
Bundle bundle = new Bundle();
5154
bundle.putString(AddEditApiaryFragment.ARGUMENT_EDIT_APIARY_ID, apiaryId + "");
5255
addEditApiaryFragment.setArguments(bundle);
5356
} else {
5457
// If new -> set add title
55-
actionBar.setTitle(R.string.add_apiary);
58+
if (actionBar != null) {
59+
actionBar.setTitle(R.string.add_apiary);
60+
}
5661
}
5762
ActivityUtils.addFragmentToActivity(getSupportFragmentManager(),
5863
addEditApiaryFragment, R.id.contentFrame);
5964
}
6065

66+
// Init db
67+
goBeesRepository = Injection.provideApiariesRepository();
68+
goBeesRepository.openDb();
69+
6170
// Create the presenter
62-
new AddEditApiaryPresenter(
63-
Injection.provideApiariesRepository(getApplicationContext()),
64-
addEditApiaryFragment, apiaryId);
71+
new AddEditApiaryPresenter(goBeesRepository, addEditApiaryFragment, apiaryId);
72+
}
73+
74+
@Override
75+
protected void onDestroy() {
76+
super.onDestroy();
77+
// Close database
78+
goBeesRepository.closeDb();
6579
}
6680

6781
@Override

app/src/main/java/com/davidmiguel/gobees/addeditapiary/AddEditApiaryContract.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,53 @@
66
/**
77
* This specifies the contract between the view and the presenter.
88
*/
9-
public class AddEditApiaryContract {
9+
public interface AddEditApiaryContract {
1010

1111
interface View extends BaseView<Presenter> {
1212

13+
/**
14+
* Shows message warning that the apiary cannot be empty.
15+
*/
1316
void showEmptyApiaryError();
1417

18+
/**
19+
* Shows save error message.
20+
*/
1521
void showSaveApiaryError();
1622

23+
/**
24+
* Goes back to apiaries activity.
25+
*/
1726
void showApiariesList();
1827

28+
/**
29+
* Sets apiary name in the text view.
30+
*
31+
* @param name apiary name.
32+
*/
1933
void setName(String name);
2034

35+
/**
36+
* Sets apiary notes in the text view.
37+
*
38+
* @param notes apiary notes.
39+
*/
2140
void setNotes(String notes);
22-
23-
boolean isActive();
2441
}
2542

2643
interface Presenter extends BasePresenter {
2744

45+
/**
46+
* Saves or updates an apiary in the repository.
47+
*
48+
* @param name apiary name.
49+
* @param notes apiary notes.
50+
*/
2851
void saveApiary(String name, String notes);
2952

53+
/**
54+
* Fill apiary data (the apiary must already exist in the repository).
55+
*/
3056
void populateApiary();
3157
}
32-
3358
}

app/src/main/java/com/davidmiguel/gobees/addeditapiary/AddEditApiaryFragment.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ public static AddEditApiaryFragment newInstance() {
3737
return new AddEditApiaryFragment();
3838
}
3939

40+
@Nullable
41+
@Override
42+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
43+
Bundle savedInstanceState) {
44+
View root = inflater.inflate(R.layout.addeditapiary_frag, container, false);
45+
nameTextView = (TextView) root.findViewById(R.id.add_apiary_name);
46+
notesTextView = (TextView) root.findViewById(R.id.add_apiary_notes);
47+
48+
setHasOptionsMenu(true);
49+
setRetainInstance(true);
50+
return root;
51+
}
52+
4053
@Override
4154
public void onActivityCreated(Bundle savedInstanceState) {
4255
super.onActivityCreated(savedInstanceState);
@@ -54,19 +67,6 @@ public void onClick(View v) {
5467
});
5568
}
5669

57-
@Nullable
58-
@Override
59-
public View onCreateView(LayoutInflater inflater, ViewGroup container,
60-
Bundle savedInstanceState) {
61-
View root = inflater.inflate(R.layout.addeditapiary_frag, container, false);
62-
nameTextView = (TextView) root.findViewById(R.id.add_apiary_name);
63-
notesTextView = (TextView) root.findViewById(R.id.add_apiary_notes);
64-
65-
setHasOptionsMenu(true);
66-
setRetainInstance(true);
67-
return root;
68-
}
69-
7070
@Override
7171
public void onResume() {
7272
super.onResume();
@@ -109,6 +109,11 @@ public void setPresenter(@NonNull AddEditApiaryContract.Presenter presenter) {
109109
this.presenter = checkNotNull(presenter);
110110
}
111111

112+
/**
113+
* Shows a snackbar with the given message.
114+
* @param view view.
115+
* @param message message to show.
116+
*/
112117
@SuppressWarnings("ConstantConditions")
113118
private void showMessage(View view, String message) {
114119
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();

0 commit comments

Comments
 (0)