Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge final fixes into master #21

Merged
merged 28 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
40eae72
Added SafeAreaView for styling on iPhone X
albullington Dec 10, 2018
203327d
Updated styling for iOS/Android based on SafeAreaView
albullington Dec 11, 2018
8bd1ee2
Added loading wheel to camera
albullington Dec 11, 2018
5888365
Updated params being passed into Camera to include null values
albullington Dec 11, 2018
ecad0a9
Added button to location picker to bring user back to current location
albullington Dec 11, 2018
b3df867
Updated icon in location picker
albullington Dec 11, 2018
78fb349
Updated location picker to use 0.2 lat/long delta
albullington Dec 12, 2018
06e2d9a
Fixed user location button on Android
albullington Dec 12, 2018
561e45f
Updated launch screen iOS and error message on Main Screen
albullington Dec 12, 2018
755ef3e
Updated badge recalculation and camera loading screen
albullington Dec 12, 2018
88b2e59
Tweaked logic in challenge results to capture null ids
albullington Dec 12, 2018
748f0fe
Capitalize species names on main banner
albullington Dec 12, 2018
3f5e886
Updated challenge results to include common ancestor
albullington Dec 12, 2018
8eeeac7
Tweaked logic for challenge results with common ancestor
albullington Dec 12, 2018
3584ad8
Tweaks to launch screen, banners, badges, and nav
albullington Dec 13, 2018
7db563e
Updated banner to use species images on main screen
albullington Dec 13, 2018
918f5e6
Created second animated toast
albullington Dec 14, 2018
478340f
Updating second banner with badge icon
albullington Dec 14, 2018
2383194
Badge banner shows with correct timing
albullington Dec 14, 2018
e1e084a
Styling tweaks in banner and results
albullington Dec 14, 2018
2ac060d
Fixed size of location in main screen header for small screens
albullington Dec 14, 2018
be01862
Updated camera nav bar for iPhone X
albullington Dec 14, 2018
9f5d3e4
Added app icon and updated number of photos in gallery
albullington Dec 14, 2018
746261e
Added launchMode: singleTask to Android manifest
albullington Dec 14, 2018
86273b2
Fixed memory leak from unmounting in Main Screen
albullington Dec 14, 2018
e57d5da
Removed console logs
albullington Dec 14, 2018
5460347
Fixed current month for fetching challenges
albullington Dec 14, 2018
5728274
Added zoom functionality to camera
albullington Dec 14, 2018
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
Prev Previous commit
Next Next commit
Badge banner shows with correct timing
  • Loading branch information
albullington committed Dec 14, 2018
commit 23831948b8538319f1858f41c2673c7e5a667178
22 changes: 11 additions & 11 deletions components/Banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import badgeImages from "../assets/badges";
import realmConfig from "../models/index";

type Props = {
bannerText: string, // add banner text 2
bannerText: string,
badgeEarned: boolean,
taxaName: string,
id: number,
main: boolean
Expand All @@ -23,6 +24,7 @@ type Props = {
class Banner extends Component {
constructor( {
bannerText,
badgeEarned,
taxaName,
id,
main
Expand All @@ -31,7 +33,8 @@ class Banner extends Component {

this.state = {
bannerText,
secondBannerText: "banner earned",
badgeEarned,
secondBannerText: "badge earned!",
taxaName,
id,
iconicTaxonId: 0,
Expand All @@ -44,12 +47,9 @@ class Banner extends Component {
}

componentDidMount() {
const { secondBannerText } = this.state;
console.log( this.state.badgeEarned, "does banner know badge earned" );
this.showToast();

if ( secondBannerText ) {
this.showSecondToast();
}
this.showSecondToast();
}

fetchTaxonId() {
Expand All @@ -64,7 +64,6 @@ class Banner extends Component {
const badges = realm.objects( "BadgeRealm" ).sorted( [["earnedDate", true], ["index", false]] );
const lastEarnedBadge = badges.slice( 0, 1 );
const lastEarnedBadgeIcon = lastEarnedBadge[0].earnedIconName;
console.log( lastEarnedBadgeIcon, "last earned badge in banner" );
this.setState( {
iconicTaxonId,
lastEarnedBadgeIcon
Expand Down Expand Up @@ -125,6 +124,7 @@ class Banner extends Component {
render() {
const {
bannerText,
badgeEarned,
secondBannerText,
iconicTaxonId,
main,
Expand Down Expand Up @@ -168,7 +168,7 @@ class Banner extends Component {
return (
<View style={styles.container}>
{banner}
{ secondBannerText ? (
{ badgeEarned ? (
<Animated.View style={[
styles.animatedStyle,
styles.secondAnimatedStyle,
Expand All @@ -180,9 +180,9 @@ class Banner extends Component {
<View style={[styles.row, styles.animatedRow]}>
<Image
source={badgeImages[lastEarnedBadgeIcon]}
style={styles.mainBannerImage}
style={styles.badgeBannerImage}
/>
<Text style={[styles.text, styles.mainText]}>{bannerText}</Text>
<Text style={[styles.text, styles.mainText]}>{secondBannerText}</Text>
</View>
</Animated.View>
) : null}
Expand Down
12 changes: 10 additions & 2 deletions components/Challenges/ChallengeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ type Props = {
setTaxonId: Function,
updateLocation: Function,
reverseGeocodeLocation: Function,
error: string
error: string,
badgeEarned: boolean
}

const ChallengeScreen = ( {
badgeCount,
badgeEarned,
taxaName,
id,
speciesCount,
Expand Down Expand Up @@ -73,7 +75,13 @@ const ChallengeScreen = ( {
>
<View style={styles.container}>
{ taxaName ? (
<Banner bannerText={`${taxaName} collected!`} main taxaName={taxaName} id={id} />
<Banner
bannerText={`${taxaName} collected!`}
main
taxaName={taxaName}
id={id}
badgeEarned
/>
) : null }
<ChallengeHeader
latitude={latitude}
Expand Down
33 changes: 27 additions & 6 deletions components/MainScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class MainScreen extends Component<Props, State> {
badgeCount: 0,
speciesCount: 0,
taxaName,
id
id,
badgeEarned: false
};

( this: any ).updateLocation = this.updateLocation.bind( this );
Expand All @@ -69,7 +70,6 @@ class MainScreen extends Component<Props, State> {
} else {
this.getGeolocation();
}
this.fetchSpeciesAndBadgeCount();
}

setTaxa( challenges: Array<Object> ) {
Expand Down Expand Up @@ -182,14 +182,33 @@ class MainScreen extends Component<Props, State> {
}

fetchSpeciesAndBadgeCount() {
let badgeCount;

Realm.open( realmConfig )
.then( ( realm ) => {
badgeCount = realm.objects( "BadgeRealm" ).filtered( "earned == true" ).length;

console.log( badgeCount, "old badge count" );
} ).catch( ( err ) => {
console.log( "[DEBUG] Failed to open realm, error: ", err );
} );

recalculateBadges();

Realm.open( realmConfig )
.then( ( realm ) => {
const newBadgeCount = realm.objects( "BadgeRealm" ).filtered( "earned == true" ).length;
const speciesCount = realm.objects( "ObservationRealm" ).length;

console.log( badgeCount, "old badge count 2" );
console.log( newBadgeCount, "new badge count" );
console.log( speciesCount, "species count" );

this.setState( {
speciesCount: realm.objects( "ObservationRealm" ).length,
badgeCount: realm.objects( "BadgeRealm" ).filtered( "earned == true" ).length
} );
speciesCount,
badgeEarned: newBadgeCount > badgeCount && speciesCount !== 0,
badgeCount: newBadgeCount
}, () => console.log( this.state.badgeEarned, "badge earned" ) );
} ).catch( ( err ) => {
console.log( "[DEBUG] Failed to open realm, error: ", err );
} );
Expand Down Expand Up @@ -246,7 +265,8 @@ class MainScreen extends Component<Props, State> {
speciesCount,
taxaType,
taxa,
id
id,
badgeEarned
} = this.state;

const {
Expand Down Expand Up @@ -275,6 +295,7 @@ class MainScreen extends Component<Props, State> {
taxaName={taxaName}
error={error}
id={id}
badgeEarned={badgeEarned}
/>
</View>
</SafeAreaView>
Expand Down
9 changes: 7 additions & 2 deletions utility/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const flattenUploadParameters = ( uri, time, latitude, longitude ) => {
type: "image/jpeg"
} ),
observed_on: new Date( time * 1000 ).toISOString(),
latitude, // need to account for null case
longitude // need to account for null case
latitude,
longitude
};
return params;
};
Expand All @@ -40,6 +40,8 @@ const reverseGeocodeLocation = ( latitude, longitude ) => {
};

const recalculateBadges = () => {
let badgeEarned = false;

Realm.open( realmConfig.default )
.then( ( realm ) => {
const collectedTaxa = realm.objects( "TaxonRealm" );
Expand All @@ -55,19 +57,22 @@ const recalculateBadges = () => {
badge.earned = true;
badge.earnedDate = new Date();
} );
badgeEarned = true;
}
} else if ( badge.count !== 0 ) {
if ( collectedTaxa.length >= badge.count ) {
realm.write( () => {
badge.earned = true;
badge.earnedDate = new Date();
} );
badgeEarned = true;
}
}
} );
} ).catch( ( err ) => {
console.log( "[DEBUG] Failed to open realm in recalculate badges, error: ", err );
} );
return badgeEarned;
};

const addToCollection = ( observation, latitude, longitude, image ) => {
Expand Down