Skip to content
Permalink
Browse files

v2.1 submitted to store. app shortcuts for 7.1 or above, cancel alarm…

… if goal is completed, fix goal creation bug where if end time is less than 15mins from now, it would fail.
  • Loading branch information...
Q115 committed Aug 19, 2018
1 parent 0a6cbcf commit 527944dc8b94a2923d94585e52bf6e03e7929ad1
@@ -35,6 +35,6 @@ Excluding all tests and layout XML files, below is the statistic for Goalie as o

<p align="center">
<br><br><br>
<a href="http://goalie.ga/termsofservice.htm">Terms of Service</a> -
<a href="http://goalie.ga/privacypolicy.htm">Privacy Policy</a>
<a href="http://goalie.es/termsofservice.htm">Terms of Service</a> -
<a href="http://goalie.es/privacypolicy.htm">Privacy Policy</a>
</p>
@@ -7,8 +7,8 @@ android {
applicationId "com.github.q115.goalie_android"
minSdkVersion 19
targetSdkVersion 27
versionCode 10
versionName "2.0"
versionCode 11
versionName "2.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -52,7 +52,7 @@ dependencies {

//FCM
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-messaging:17.3.0'

//crop image
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
@@ -28,9 +28,6 @@
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

<!-- Accepts URIs that begin with "goalie://goals" -->
<action android:name="android.intent.action.VIEW"/>

@@ -41,6 +38,10 @@
android:host="goals"
android:scheme="goalie"/>
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
</activity>
<activity
android:name=".ui.profile.ProfileActivity"
@@ -90,6 +91,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/files"/>
</provider>
<receiver android:name=".services.AlarmService" />
<receiver android:name=".services.AlarmService"/>
</application>
</manifest>
@@ -16,7 +16,7 @@
* limitations under the License.
*/
public class Constants {
public static final String URL = BuildConfig.DEBUG ? "http://104.197.166.11:8080" : "http://goalie.ga";
public static final String URL = BuildConfig.DEBUG ? "http://104.197.166.11:8080" : "http://goalie.es";
public static final String KEY = BuildConfig.DEBUG ? "xxx" : "xxxx";
public static final String CUSTOM_KEY = BuildConfig.DEBUG ? "CUSTOM_KEY" : "CUSTOM_KEY_PROD";
public static final String PREFERENCE_FILE_NAME = "PREFERENCE_FILE_NAME";
@@ -1,5 +1,7 @@
package com.github.q115.goalie_android.https;

import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
@@ -46,14 +48,16 @@
private RESTSync.Listener mListener;
private final long mLastSyncedTimeEpoch;
private static boolean isSyncing;
private Context context;

public static boolean isSyncing() {
return isSyncing;
}

public RESTSync(String username, long lastSyncedTimeEpoch) {
public RESTSync(String username, long lastSyncedTimeEpoch, Context context) {
this.mUsername = username;
mLastSyncedTimeEpoch = lastSyncedTimeEpoch;
this.context = context;
}

public interface Listener extends RESTBaseListener {
@@ -178,6 +182,7 @@ private void setupMyGoals(JSONArray jsonMy) throws Exception {

localActiveGoal.goalCompleteResult = fetchedGoal.goalCompleteResult;
GoalHelper.getInstance().modifyGoal(localActiveGoal);
GoalHelper.getInstance().cancelAlarm(localActiveGoal.guid, context);
}
}
}
@@ -112,7 +112,7 @@ private void request() {

private void sync() {
RESTSync sm = new RESTSync(UserHelper.getInstance().getOwnerProfile().username,
PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), this);
sm.setListener(new RESTSync.Listener() {
@Override
public void onSuccess() {
@@ -56,7 +56,7 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
@Override
public void onRefresh() {
RESTSync sm = new RESTSync(UserHelper.getInstance().getOwnerProfile().username,
PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), getActivity());
sm.setListener(new RESTSync.Listener() {
@Override
public void onSuccess() {
@@ -271,6 +271,8 @@ private void delete() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
GoalHelper.getInstance().deleteGoal(mGuid);
GoalHelper.getInstance().cancelAlarm(mGuid, getActivity());

Intent returnIntent = new Intent();
String goalCompleteResultString = String.valueOf(Goal.GoalCompleteResult.Cancelled.ordinal());
returnIntent.putExtra("goalCompleteResultInt", goalCompleteResultString);
@@ -100,7 +100,7 @@ protected void onResume() {
@Override
protected void onStart() {
super.onStart();
mPresenter.start();
mPresenter.syncIfNeeded(this);
}

@Override
@@ -1,5 +1,6 @@
package com.github.q115.goalie_android.ui.main;

import android.content.Context;
import android.support.annotation.NonNull;

import com.github.q115.goalie_android.https.RESTSync;
@@ -33,13 +34,16 @@ public MainActivityPresenter(@NonNull MainActivityView mainActivityView) {
}

public void start() {
}

public void syncIfNeeded(Context context) {
String accountUsername = PreferenceHelper.getInstance().getAccountUsername();
if (accountUsername == null || accountUsername.isEmpty()) {
mMainActivityView.showLogin();
} else if (!isSyncedOnStartup) {
isSyncedOnStartup = true;
mMainActivityView.updateProgress(true);
RESTSync sm = new RESTSync(UserHelper.getInstance().getOwnerProfile().username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
RESTSync sm = new RESTSync(UserHelper.getInstance().getOwnerProfile().username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), context);
sm.setListener(new RESTSync.Listener() {
@Override
public void onSuccess() {
@@ -245,7 +245,7 @@ public void updateProgress(boolean shouldShow) {
@Override
public void setAlarmTime(long epoch, String guid) {
Intent intent = AlarmService.newIntent(getActivity(), guid);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), guid.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager alarmMgr = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmMgr.setExact(AlarmManager.RTC_WAKEUP, epoch, pendingIntent);
@@ -94,7 +94,7 @@ public void restore(HashMap<String, String> values) {
}

public String[] getAlarmReminderArray() {
return new String[]{"15 Minutes Before", "1 Hour Before", "1 Day Before"};
return new String[]{"15 Minutes Before", "1 Hour Before", "1 Day Before", "None"};
}

public long getAlarmMillisecondBeforeEndDate(int option) {
@@ -108,6 +108,9 @@ public long getAlarmMillisecondBeforeEndDate(int option) {
case 2:
mAlarmTimeBeforeEnd = 24 * 60 * 60000;
break;
case 3:
mAlarmTimeBeforeEnd = 0;
break;
default:
mAlarmTimeBeforeEnd = 0;
break;
@@ -285,6 +288,7 @@ private boolean checkGoalIsValid(Context context, String title, String referee,
}

private void setAlarmTime(String guid) {
mNewGoalView.setAlarmTime(mEnd - mAlarmTimeBeforeEnd, guid);
if (mAlarmTimeBeforeEnd > 0)
mNewGoalView.setAlarmTime(mEnd - mAlarmTimeBeforeEnd, guid);
}
}
@@ -1,10 +1,16 @@
package com.github.q115.goalie_android.utils;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.github.q115.goalie_android.Diagnostic;
import com.github.q115.goalie_android.models.Goal;
import com.github.q115.goalie_android.models.GoalFeed;
import com.github.q115.goalie_android.models.Goal_Table;
import com.github.q115.goalie_android.models.User;
import com.github.q115.goalie_android.services.AlarmService;
import com.raizlabs.android.dbflow.sql.language.SQLite;

import java.util.ArrayList;
@@ -123,4 +129,11 @@ public boolean modifyGoal(Goal goal) {
return false;
}
}

public void cancelAlarm(String guid, Context context) {
Intent intent = AlarmService.newIntent(context, guid);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, guid.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmMgr.cancel(pendingIntent);
}
}
@@ -65,7 +65,7 @@
<string name="add">Add</string>
<string name="already_friends">Already friends with this user.</string>
<string name="no_self">Cannot add yourself as a friend.</string>
<string name="join_me">Help me reach my goals by being my Referee! Join Goalie with me at http://goalie.ga/dl</string>
<string name="join_me">Help me reach my goals by being my Referee! Join Goalie with me at http://goalie.es/dl</string>
<string name="refresh">Refresh</string>

<!-- Login -->
@@ -0,0 +1,14 @@
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@mipmap/ic_launcher_round"
android:shortcutId="NewGoal"
android:shortcutLongLabel="@string/fab_new"
android:shortcutShortLabel="@string/fab_new">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.github.q115.goalie_android.ui.new_goal.NewGoalActivity"
android:targetPackage="com.github.q115.goalie_android">
</intent>
</shortcut>
</shortcuts>
@@ -1,5 +1,7 @@
package com.github.q115.goalie_android.httpTest;

import android.content.Context;

import com.github.q115.goalie_android.https.RESTNewGoal;
import com.github.q115.goalie_android.https.RESTSync;
import com.github.q115.goalie_android.utils.GoalHelper;
@@ -8,6 +10,7 @@

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.Pair;
@@ -35,6 +38,9 @@
*/
@RunWith(RobolectricTestRunner.class)
public class RESTSyncTest extends BaseRESTTest {
@Mock
Context mMockContext;

@Test()
public void sync() throws Exception {
final Pair<Integer, RESTSync.Listener> pair = createAListener();
@@ -45,7 +51,7 @@ public void sync() throws Exception {
public void onSuccess(String guid) {
assertTrue(guid != null);
assertEquals(GoalHelper.getInstance().getFeeds().size(), 0);
RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), mMockContext);
sm2.setListener(pair.second);
sm2.execute();
}
@@ -73,7 +79,7 @@ public void onFailure(String errMsg) {
public void onResponseEmpty() throws Exception {
final Pair<Integer, RESTSync.Listener> pair = createAListener();

RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), mMockContext);
sm2.setListener(pair.second);
sm2.onResponse("");

@@ -84,7 +90,7 @@ public void onResponseEmpty() throws Exception {
public void onResponseBasic() throws Exception {
final Pair<Integer, RESTSync.Listener> pair = createAListener();

RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), mMockContext);
sm2.setListener(pair.second);
sm2.onResponse("{\"feed\":[], \"my\":[],\"referee\":[],\"info\":{\"reputation\":999},\"time\":123}");

@@ -101,7 +107,7 @@ public void onResponseBasic() throws Exception {
public void onResponseInvalid() throws Exception {
final Pair<Integer, RESTSync.Listener> pair = createAListener();

RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch());
RESTSync sm2 = new RESTSync(username, PreferenceHelper.getInstance().getLastSyncedTimeEpoch(), mMockContext);
sm2.setListener(pair.second);
sm2.onResponse("{\"feed\":[], \"my\":[],\"referee\":[],\"info\":{\"reputation\":999},\"time\":\"invalid\"}");

@@ -1,5 +1,7 @@
package com.github.q115.goalie_android.httpTest;

import android.content.Context;

import com.github.q115.goalie_android.https.RESTNewGoal;
import com.github.q115.goalie_android.https.RESTSync;
import com.github.q115.goalie_android.https.RESTUpdateGoal;
@@ -8,6 +10,7 @@

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.Pair;
@@ -35,6 +38,9 @@
public class RESTUpdateGoalTest extends BaseRESTTest {
private boolean isSettingUpGoal;

@Mock
Context mMockContext;

@Test()
public void acceptGoal() throws Exception {
final Pair<Integer, RESTUpdateGoal.Listener> pair = createAListener();
@@ -142,7 +148,7 @@ private void setupGoal() throws Exception {
@Override
public void onSuccess(String guid) {
assertTrue(guid != null);
RESTSync sm = new RESTSync(username, 0);
RESTSync sm = new RESTSync(username, 0, mMockContext);
sm.setListener(new RESTSync.Listener() {
@Override
public void onSuccess() {
@@ -1,5 +1,7 @@
package com.github.q115.goalie_android.presenterTest;

import android.content.Context;

import com.github.q115.goalie_android.BaseTest;
import com.github.q115.goalie_android.Constants;
import com.github.q115.goalie_android.ui.main.MainActivityPresenter;
@@ -36,6 +38,9 @@
*/
@RunWith(RobolectricTestRunner.class)
public class MainActivityPresenterUnitTest extends BaseTest {
@Mock
Context mMockContext;

private MainActivityPresenter mPresenter;

@Mock
@@ -50,15 +55,15 @@ public void setup() {
@Test
public void onStartNotRegistered() throws Exception {
PreferenceHelper.getInstance().setAccountUsername("");
mPresenter.start();
mPresenter.syncIfNeeded(mMockContext);
verify(mView).showLogin();
}

@Test
public void onStartRegistered() throws Exception {
PreferenceHelper.getInstance().setAccountUsername(getValidFriendUsername());
UserHelper.getInstance().getOwnerProfile().username = getValidFriendUsername();
mPresenter.start();
mPresenter.syncIfNeeded(mMockContext);

verify(mView, timeout(Constants.ASYNC_CONNECTION_EXTENDED_TIMEOUT).times(1)).reloadAll();
}
@@ -10,7 +10,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3',
classpath 'com.android.tools.build:gradle:3.1.4',
'com.google.gms:google-services:4.0.1' //FCM

// NOTE: Do not place your application dependencies here; they belong

0 comments on commit 527944d

Please sign in to comment.
You can’t perform that action at this time.